in reply to Re^6: OT: Locking and syncing mechanisms available on *nix.
in thread OT: Locking and syncing mechanisms available on *nix.
libpthread is POSIX, so it should be available anywhere.#include <pthread.h> pthread_mutex_t lock; pthread_cond_t cond; int ready; void consumer() { pthread_mutex_lock(&lock); while (!ready) pthread_cond_wait(&cond, &lock); /* lock is locked, ready is true */ ready = 0; pthread_mutex_unlock(&lock); } void producer() { /* lock is unlocked */ pthread_mutex_lock(&lock); ready = 1; pthread_cond_signal(&cond, &lock); /* lock is still locked */ pthread_mutex_unlock(&lock); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: OT: Locking and syncing mechanisms available on *nix.
by BrowserUk (Patriarch) on Mar 27, 2011 at 16:11 UTC | |
by educated_foo (Vicar) on Mar 27, 2011 at 16:30 UTC | |
by BrowserUk (Patriarch) on Mar 27, 2011 at 17:59 UTC | |
by educated_foo (Vicar) on Mar 27, 2011 at 21:29 UTC | |
by BrowserUk (Patriarch) on Mar 27, 2011 at 21:40 UTC |