pthread_cond_signal
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > pthread_cond_signal




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    pthread_cond_signal  
vertigo


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-17-04 12:45 AM

Hello
i have such code in one thread1:

pthread_mutex_lock(m)
if (something)
pthread_cond_signal(c)
pthread_mutex_unlock(m)

and in thread2:
pthread_mutex_lock(m)
if (something2)
pthread_cond_wait(c,m)
pthread_mutex_unlock(m)

Thread2 wait on pthread_cond_wait(), and after that Thread1 calls
pthread_cond_signal(). I am not sure what is next. Does:

in this moment thread1 calls pthread_mutex_unlock(m), and after that
thread2 receives mutex m, and then unlock it and finishes ?
So in such case Thread2 does not start immediately after receiving
signal on conditional value, because it must wait for mutex, am i right ?

Thanx
Michal







[ Post a follow-up to this message ]



    Re: pthread_cond_signal  
Sebastien Decugis


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-17-04 07:49 AM


> in this moment thread1 calls pthread_mutex_unlock(m), and after that
> thread2 receives mutex m, and then unlock it and finishes ?
> So in such case Thread2 does not start immediately after receiving
> signal on conditional value, because it must wait for mutex, am i right ?

You are right 
The thread has to re-acquire the mutex ownership before it can leave the
pthread_cond_wait routine. (This is also true on cancellation or timer
expiration with pthread_cond_timedwait).

Regards,
Seb.





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 01:01 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register