Find the answer to your Linux question:
Results 1 to 2 of 2
Hi all, Need help in understanding the the behavior of pthread lib in following situation? I am getting a deadlock situation. One producer thread gives pthread_cond_signal to two different threads ...
  1. #1
    Just Joined!
    Join Date
    May 2007
    Posts
    2

    pthread_cond_signal query

    Hi all,

    Need help in understanding the the behavior of pthread lib in following situation? I am getting a deadlock situation.

    One producer thread gives pthread_cond_signal to two different threads (one Consumer thread and other one waiting producer thread) on two different conditions before unlocking the mutex. Both of these conditions are getting fullfilled at the same time and producer thread first singals the consumer thread and then signals the waiting producer thread. After that it releases the mutex by calling unlock on it.

    Firstly, which thread would get the mutex? Consumer or Waiting producer thread?

    Secondly, If one these two threads got the mutex, what will happen to other thread? will it still wait for mutex/next singal or will get blocked forever?

    I am ruling out signal lose (if any) will block any thread forever, because if one thread misses any signal, it will get another signal after condition satifies.

    Thanks in advance!!
    -Tarun

  2. #2
    Just Joined!
    Join Date
    Feb 2007
    Posts
    14

    Hope this is useful!

    If more than one thread is blocked on a condition variable, the scheduling policy determines the order in which threads are unblocked. When each thread unblocked as a result of a pthread_cond_signal() or pthread_cond_broadcast() returns from its call to pthread_cond_wait() or pthread_cond_timedwait(), the thread owns the mutex with which it called pthread_cond_wait() or pthread_cond_timedwait(). The thread(s) that are unblocked contend for the mutex according to the scheduling policy and as if each had called pthread_mutex_lock().

    So for your case, the two threads will actually contest for the mutex lock and only one of them will get it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...