Semaphore implementation for the synchronization of POSIX threads. More...
Go to the source code of this file.
Typedefs | |
| typedef struct SEM | SEM |
Functions | |
| SEM * | sem_init (int initVal) |
| Creates a new semaphore. | |
| int | sem_del (SEM *sem) |
| Destroys a semaphore and frees all associated resources. | |
| void | P (SEM *sem) |
| P-operation. | |
| void | V (SEM *sem) |
| V-operation. | |
Semaphore implementation for the synchronization of POSIX threads.
This module implements counting P/V semaphores suitable for the synchronization of POSIX threads. POSIX mutexes and condition variables are utilized to implement the semaphor operations.
| void P | ( | SEM * | sem | ) |
P-operation.
Attempts to decrement the semaphore value by 1. If the semaphore value is 0, the operation blocks until a V-operation increments the value and the P-operation succeeds.
| sem | Handle of the semaphore to decrement. |
| int sem_del | ( | SEM * | sem | ) |
Destroys a semaphore and frees all associated resources.
If an error occurs, errno is set to an appropriate value.
| sem | Handle of the semaphore to destroy. |
| SEM* sem_init | ( | int | initVal | ) |
Creates a new semaphore.
This function creates a new semaphore. If an error occurs during the initialization, the implementation frees all resources already allocated by then and sets errno to an appropriate value.
| initVal | The initial value of the semaphore. |
NULL if an error occurred. | void V | ( | SEM * | sem | ) |
V-operation.
Increments the semaphore value by 1 and notifies P-operations that are blocked on the semaphore of the change.
| sem | Handle of the semaphore to increment. |
1.7.1