Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. Clever Code
  4. Things which make debugging Multi-Threaded applications more difficult [modified]

Things which make debugging Multi-Threaded applications more difficult [modified]

Scheduled Pinned Locked Moved Clever Code
debugginghelpc++data-structuresquestion
1 Posts 1 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rama Krishna Vavilala
    wrote on last edited by
    #1

    Thread 1 code sequence goes like this.

    AnotherFuncThatGetsExclusiveAccessToTheObject();

    ASSERT(IHaveExclusiveAccess());

    DoSomethingWithTheObject();
    AnotherFuncThatReleasesExclusiveObject();
    DoSomeOtherThing();
    DoSomethingElseUnrelated();

    Thread 2 code goes like this:

    GetExclusiveAccessToTheObject();

    //Make sure that our locking mechanism is working
    ASSERT(IHaveExclusiveAccess());

    DoSomethingWithTheObject();
    ReleaseExclusiveObject();

    The ASSERT's (standard VC++ asserts unmodified) where added to make sure that the locking code worked and only one thread has exclusive access to an object. The idea was that if there is a bug in the locking code and by chance two threads have same access the ASSERT will indicate the error and break in the debugger. The debugger call stack can then be inspected to see what other threads are doing and which other thread accessed the object. However, this never works in practice without writing a custom ASSERT. Why? -- modified at 17:29 Sunday 24th September, 2006


    Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups