sem_init¶
sem_init() initializes an unnamed POSIX semaphore.
Prototype¶
Parameters¶
| Parameter | Description |
|---|---|
sem |
Semaphore object to initialize |
pshared |
0 for thread-shared, non-zero for process-shared |
value |
Initial semaphore count |
Typical Process-Shared Usage¶
Return Value¶
0on success-1on error, witherrnoset
Common Pitfalls¶
Warning
For process-shared use, the sem_t object must be stored in shared memory.
Note
Use sem_wait() to consume a count and sem_post() to produce a count.