| 
                  Notifying Threads of State Changes
                   in Pthreads  | 
            
| 
                   
                      
                     Prof. David Bernstein
                       | 
            
| Computer Science Department | 
| bernstdh@jmu.edu | 
               
            
         
            
         
         
            
         
         
            
         
         
            
         
         
            
         pthread_cond_t variables
         
            
         
         
            
         static pthread_cond_t example = PTHREAD_COND_INITIALIZER
                     
         
            
         
         
            
         
         
            
         
         
            
         int pthread_cond_wait(pthread_cond_t *cv, pthread_mutex_t *mutex)
               
                        cv
                      | 
                     The condition variable to wait for | 
                        mutex
                      | 
                     The mutex associated with the condition variable | 
| Return | 0 on success; a positive error number on error | 
    When Called: mutex is relinquished and the calling thread
    is blocked.
  
    When Unblocked: mutex is obtained (so that the shared variable
    can be used).
  
         
            
         pthread_cond_wait() returns when notified
	      but there is no guarantee that the predicate is satisfied
	      so it must be re-checked
	      
         
            
         
         
            
         int pthread_cond_broadcast(pthread_cond_t *cv)
               
                        cv
                      | 
                     The condition variable the threads are/may be blocking on | 
| Return | 0 on success; a positive error number on error | 
Note: All blocking threads will be notified but which one(s) are scheduled is arbitrary.
         
            
         int pthread_cond_init(pthread_cond_t *cv, const pthread_condattr_t *attr)
               
                        cv
                      | 
                     The condition variable to be initialized | 
                        attr
                      | 
                     The attributes to use (of NULL for the default attributes) | 
| Return | 0 on success; a positive error number on error |