- 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. 1.2.2) presents a function that initializes a binary semaphore.
Figure 5:
Initializing a Binary Semaphore
|
2006-03-31