pthread_cond_broadcast() — Broadcast a condition

Standards

Standards / Extensions C or C++ Dependencies

POSIX.4a
Single UNIX Specification, Version 3

both

POSIX(ON)

Format

#define _OPEN_THREADS
#include <pthread.h>

int pthread_cond_broadcast(pthread_cond_t *cond);
SUSV3:
#define _UNIX03_THREADS
#include <pthread.h>

int pthread_cond_broadcast(pthread_cond_t *cond);

General description

Unblock all threads that are blocked on the specified condition variable, cond. If more than one thread is blocked, the order in which the threads are unblocked is unspecified.

pthread_cond_broadcast() has no effect if there are no threads currently blocked on cond.

Returned value

If successful, pthread_cond_broadcast() returns 0.

If unsuccessful, pthread_cond_broadcast() returns -1 and sets errno to one of the following values:
Error Code
Description
EINVAL
The value specified by cond does not refer to an initialized condition variable.

Special behavior for Single UNIX Specification, Version 3:

If unsuccessful, pthread_cond_broadcast() returns an error number to indicate the error.

Example

CELEBP17
⁄* CELEBP17 *⁄                                   
#define _OPEN_THREADS                                                           
#include <pthread.h>                                                            
#include <stdio.h>                                                              
                                                                                
main() {                                                                        
  pthread_cond_t cond;                                                          
                                                                                
  if (pthread_cond_init(&cond, NULL) != 0) {                                    
    perror("pthread_cond_init() error");                                        
    exit(1);                                                                    
  }                                                                             
                                                                                
  if (pthread_cond_broadcast(&cond) != 0) {                                     
    perror("pthread_cond_broadcast() error");                                   
    exit(2);                                                                    
  }                                                                             
                                                                                
  if (pthread_cond_destroy(&cond) != 0) {                                       
    perror("pthread_cond_destroy() error");                                     
    exit(3);                                                                    
  }                                                                             
}                                                                               

Related information