Hardware Reference
In-Depth Information
cond : Pointer to the condition variable to be used for the wake-
up call.
mutex : Pointer to the mutex to be associated with the condition
variable.
returns : Returns zero upon success; otherwise, an error code
is returned (not in errno ).
Error
Description
EINVAL
The value specified by cond, mutex is invalid. Or different mutexes were
supplied for concurrent pthread_cond_timedwait() or pthread_cond_
wait() operations on the same condition variable.
EPERM
The mutex was not owned by the current thread at the time of the call.
The following code snippet shows how a queuing function would use this.
(Initialization of mutex and cond is assumed.)
pthread_mutex_t mutex;
pthread_cond_t cond;
...
pthread_mutex_lock(&mutex);
while ( queue.length >= max_length )
pthread_cond_wait(&cond,&mutex);
// queue the item
...
pthread_mutex_unlock(&mutex);
The while loop retries the test to see whether the queue is “not full.” The while loop
is necessary when multiple threads are inserting into the queue. Depending on timing,
another thread could beat the current thread to queuing an item, making the queue full
again.
pthread_cond_signal(3)
When an item is taken off the queue, a mechanism needs to wake up the thread
attempting to put one entry into the full queue. One wake-up option is the
pthread_cond_signal(3) system call:
int pthread_cond_signal(pthread_cond_t
cond);
 
 
Search WWH ::




Custom Search