Unix Programming - pthread_cond_signal

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > December 2004 > pthread_cond_signal





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author pthread_cond_signal
vertigo

2004-12-16, 7:45 pm

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


Sebastien Decugis

2004-12-17, 2: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.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com