| |
Linux API for Semaphores
- Semget
- To get an array of semaphores
- Semctl
- Semaphore controls. For example initial value
- Semop
- Semaphore Operations (lock, signal etc.)
Pthread Mutex Locks
- Data Types: pthread_mutex_t
- Creation: pthread_mutex_init
- Lock: pthread_mutex_lock
- Unlock: pthread_mutex_unlock
pthread_mutex_t mutex;
pthread_mutex_init(&mutex, NULL);
pthread_mutex_lock(&mutex);
pthread_mutex_unlock(&mutex);
Win32 Mutex Locks and Semaphores
- Declaration
- HANDLE mutex; (or HANDLE semaphore);
- Creation
- CreateMutex: To create a mutex lock
- CreateSemaphore: To create a semaphore
- semaphore = CreateSemaphore(NULL, 1, 5, NULL);
- Wait for mutex or semaphore
- WaitForSingleObject(HANDLE, WAITTYPE)
- Releasing
- ReleaseMutex(mutex)
- ReleaseSemaphore(sem, 1, NULL)
|