[clug] pthread coroutines

Eyal Lebedinsky eyal at eyal.emu.id.au
Wed Jul 2 19:33:58 EST 2003


Simon Burton wrote:
> 
> Hi,
> 
> How to use mutexes so that effectively only one out of two threads
> is running at a time? Like co-routines. Each thread blocks on a
> pthread_mutex_lock() while the other is running. I'm sure it will come to me
> eventually. Or is there Another Way?

Yes, you use mutexes (or some other related synchronization verbs).
However, there is no telling who will run after you release a lock
and then aquire it again. You may get it or the other process may
get it first. In other words, fairness is not guaranteed.

--
Eyal Lebedinsky (eyal at eyal.emu.id.au) <http://samba.org/eyal/>



More information about the linux mailing list