[clug] pthread coroutines
Simon Burton
simon at arrowtheory.com
Wed Jul 2 22:21:59 EST 2003
Thanks, this looks right;; i tried two mutexes and was thinking i'd need three ...
Simon.
On Wed, 2 Jul 2003 22:00:41 +1000
Andrew Over <andrew at cs.anu.edu.au> wrote:
> Condition variable and a mutex. Every time you want to change the
> active thread (ie you're done):
>
> pthread_mutex_lock(&mtx);
> pthread_cond_signal(&cvar);
> pthread_cond_wait(&cvar, &mtx);
> pthread_mutex_unlock(&mtx);
>
> The mutex is only necessary to avoid a race condition between a thread
> trying to wait and a thread trying to signal.
>
> Cheers,
> --Andrew
>
--
Simon Burton, B.Sc.
Licensed PO Box A66
ANU Canberra 2601
Australia
Ph. 02 6249 6940 \
------------------------\
------------------------/
http://arrowtheory.com /
More information about the linux
mailing list