Next: Wait and Post Operations
 Up: Processes Semaphores
 Previous: Allocation and Deallocation
     Contents 
- Allocating and initializing semaphores are two separate operations.
- To initialize a semaphore, use semctl with zero as the second argument, 
 
- SETALL as the third argument,
 
- For the fourth argument, you must create a union semun object and point its array field at an array of unsigned short values. Each value is used to initialize one semaphore in the set. 
 
 
- The following http://siber.cankaya.edu.tr/SystemsProgramming/cfiles/sem_init.ccode (see Fig. 6.2.2) presents a function that initializes a binary semaphore.
Figure 6.3:
Initializing a Binary Semaphore
  | 
 
 
Cem Ozdogan
2007-05-16