324_Book

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: that a call to pthread mutex wait must always be protected by that mutex: 1 2 3 Pthread_mutex_lock(&mutex); Pthread_cond_wait(&cond, &mutex); Pthread_mutex_unlock(&mutex); The call to pthread cond wait releases the mutex and suspends the current thread until cond becomes true. At this point, we say that the current thread is waiting on condition variable cond. Later, someother thread indicates that the condition associated with cond has become true by making a call to the pthread cond signal function: 1 Pthread_cond_signal(&cond); If there are any threads waiting on condition cond, then the call to pthread cond signal sends a signal that wakes up exactly one of them. The thread that wakes up as a result of the signal reacquires the mutex and then returns from its call to pthread cond wait. If no threads are currently waiting on condition cond, then nothing happens. Thus, like Unix signals, and unlike Posix semaphores, Pthreads signals are not queued, which makes them much harder to reason abou...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online