Sistemi operativi - Syscall pthread_cond_wait
The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group
pthread_cond_wait, pthread_cond_timedwait - wait on a condition
int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
int pthread_cond_timedwait(pthread_cond_t *cond,
pthread_mutex_t *mutex, const struct timespec *abstime);
The pthread_cond_wait() and pthread_cond_timedwait() functions are used to block on a
condition variable. They are called with mutex locked by the calling thread or undefined
behaviour will result.
These functions atomically release mutex and cause the calling thread to block on the
condition variable cond; atomically here means "atomically with respect to access by another
thread to the mutex and then the condition variable". That is, if another thread is able to
acquire the mutex after the about-to-block thread has released it, then a subsequent call to
pthread_cond_signal() or pthread_cond_broadcast() in that thread behaves as if it were
issued after the about-to-block thread has blocked.
Upon successful return, the mutex has been locked and is owned by the calling thread.
When using condition variables there is always a boolean predicate involving shared variables
associated with each condition wait that is true if the thread should proceed. Spurious
wakeups from the pthread_cond_wait() or pthread_cond_timedwait() functions may occur.
Since the return from pthread_cond_wait() or pthread_cond_timedwait() does not imply
anything about the value of this predicate, the predicate should be re-evaluated upon such
The effect of using more than one mutex for concurrent pthread_cond_wait() or
pthread_cond_timedwait() operations on the same condition variable is undefined; that is, a
condition variable becomes bound to a unique mutex when a thread waits on the condition
variable, and this (dynamic) binding ends when the wait returns.
A condition wait (whether timed or not) is a cancellation point. When the cancelability enable
state of a thread is set to PTHREAD_CANCEL_DEFERRED, a side effect of acting upon a
cancellation request while in a condition wait is that the mutex is (in effect) re-acquired
before calling the first cancellation cleanup handler. The effect is as if the thread were
unblocked, allowed to execute up to the point of returning from the call to
pthread_cond_wait() or pthread_cond_timedwait(), but at that point notices the cancellation
request and instead of returning to the caller of pthread_cond_wait() or
pthread_cond_timedwait(), starts the thread cancellation activities, which includes calling
cancellation cleanup handlers.
A thread that has been unblocked because it has been canceled while blocked in a call to
1 di 3 10/06/2010 16:28
+1 anno fa
I contenuti di questa pagina costituiscono rielaborazioni personali del Publisher N. A. di informazioni apprese con la frequenza delle lezioni di Sistemi operativi e studio autonomo di eventuali libri di riferimento in preparazione dell'esame finale o della tesi. Non devono intendersi come materiale ufficiale dell'università Napoli Federico II - Unina o del prof Cotroneo Domenico.
Acquista con carta o conto PayPal
Scarica il file tutte le volte che vuoi
Paga con un conto PayPal per usufruire della garanzia Soddisfatto o rimborsato