Thread: race condition detection tool

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    11

    race condition detection tool

    I am searching for a tool that can detect race conditions. Does anybody use such a thing?

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Unlikely. The only way to detect race conditions is by looking for evidence of whatever happens when when they occur (eg variables having unexpected values, lockups). The problem is that there is virtually an infinite number of ways to cause race conditions, and a virtually infinite way to trigger them at run time. Writing a tool to detect all possible race conditions would therefore be somewhat challenging.

    The basic rule with race conditions is "prevention is better than cure". The usual way to prevent race conditions is through analysis to identify what conditions may cause a race condition, and modify design to ensure those conditions do not occur.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Apr 2009
    Posts
    11
    @grumpy: The problem here is, that I've followed the safest multithreading route - no shared variables (or at least I think so, I checked several times). But the situations at which the problems appear (depends on the number of threads, and if I put random usleep the problem disappears, valgrind doesn't show invalid read/writes) suggests that race condition is the problem. I think I may accidently used some shared memory, because there's nothing other I can think of.

    @Salem: I will see this. I already use valgrind for memory leak checking, but I didn't know it can detect race conditions.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Keep reading, there are other 'grind' tools.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6

  7. #7
    Registered User
    Join Date
    Apr 2009
    Posts
    11
    Thanks guys. It turned out that the bug wasn't race condition. It was an algorithm error that appeared randomly in specific situations when the network delivered very few bytes. usleep probbably stopped the problem by giving more time tcp buffer to fill and having more threads ment more connections which ment just a higher probabbility of the error occuring. I really thought that it is a race condition, but it wasn't. However I will use the tools given on my others projects. Thanks for the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 06-02-2009, 08:57 PM
  2. Problems reading entered race times C
    By loopymoo26 in forum C Programming
    Replies: 12
    Last Post: 05-23-2009, 07:38 AM
  3. Race Condition Help
    By Nor in forum C++ Programming
    Replies: 3
    Last Post: 02-25-2009, 07:43 PM
  4. Race condition: getting multiple threads to cooperate
    By FlyingDutchMan in forum C++ Programming
    Replies: 10
    Last Post: 03-31-2005, 05:53 AM
  5. Race condition
    By Roaring_Tiger in forum C Programming
    Replies: 5
    Last Post: 10-24-2004, 09:42 PM