In unix how we can test or check race condition in c program by using multi threads

Discussion in 'Programming' started by azaz, Feb 24, 2009.

  1. azaz

    azaz New Member

    Joined:
    Feb 24, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    In unix how we can test or check race condition in any c program by using multi thread programming
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Re: In unix how we can test or check race condition in c program by using multi thre

    Could you give more details about what problem you're trying to solve? The question as stated doesn't make a lot of sense. A race condition is where the behaviour of the application critically depends on things happening in a specific order but where the order hasn't been enforced with critical sections, mutexes or other suitable lockout mechanisms, and typically you would know about them by the application intermittently not working properly, the actual behaviour depending on what exactly doesn't go in what order and what the implications of the reordering are. Consequently testing for them can be extremely difficult as the behaviour depends on many things including the overall system performance.

    While race conditions can show up in multithreaded programs they can also show up in single threaded event-driven programs.
     
  3. azaz

    azaz New Member

    Joined:
    Feb 24, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Re: In unix how we can test or check race condition in c program by using multi thre

    Hi,
    Thanks 4 ur concern. I want to know any way is there to know race condition happening while executing the code.
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Re: In unix how we can test or check race condition in c program by using multi thre

    If the order of events is not sequenced then you will get race conditions. For example if you have thread 1 that does tasks A,B,C, and thread 2 that does D,E,F, the only thing you can be certain of is that A will be done before B which will be done before C and likewise for D,E,F, you can't know whether any of A,B,C will occur before or after any of D,E,F. So if, for example, F is dependent on A and B having completed, then you must enforce a sequence point before F is allowed to start, for example:

    thread 1:
    perform A
    perform B
    set flag "A and B complete"
    perform C

    thread 2:
    perform D
    perform E
    if flag "A and B complete" is not set wait until it is
    perform F.

    So in fact race conditions happen all the time, and without the AB flag we have no way of knowing if the completed event sequence in this example will be AD BE CF, or AB DE CF, or ABC DEF, or D ABC EF, or A DEF BC etc. A race condition only matters when something in one thread is dependent on something in another; if that is not the case in your application then you don't need to worry about race conditions.
     
  5. azaz

    azaz New Member

    Joined:
    Feb 24, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Re: In unix how we can test or check race condition in c program by using multi thre

    HI,
    Thanks 4 ur concern .
    And i need to know after compilation or while compilattion how we can say any programme is victim of Race Condition or not
     
  6. azaz

    azaz New Member

    Joined:
    Feb 24, 2009
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Re: In unix how we can test or check race condition in c program by using multi thre

    Hi,

    My actual problem is below one. And iam mnot getting any idea please help me in this
    Developing a script to detect race conditions in a given library or code using multi-thread programminging.
     
  7. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Re: In unix how we can test or check race condition in c program by using multi thre

    As far as I know this is not actually possible, and you have to design race conditions out rather than try to detect them after the event. If your code is modular with clean interfaces and limited or non-existent interdependency then it will be relatively easy for a human programmer to review the code and determine what might exist.

    Essentially what you're asking for is an automated tool that detects bugs. No such thing I'm afraid. Good design and thorough testing is the only general solution for bugs.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice