Operating System semaphore - What is a semaphore?
What is a semaphore? A semaphore is a variable. There are 2 types of semaphores:
- Binary semaphores have 2 methods associated with it. (up, down / lock, unlock)
- Binary semaphores can take only 2 values (0/1). They are used to acquire locks. When a resource is available, the process in charge set the semaphore to 1 else 0.
- Counting Semaphore may have value to be greater than one, typically used to allocate resources from a pool of identical resources
What is difference between binary semaphore and mutex?The differences between binary semaphore and mutex are:
- Mutex is used exclusively for mutual exclusion. Both mutual exclusion and synchronization can be used by binary.
- A task that took mutex can only give mutex.
- From an ISR a mutex can not be given.
- Recursive taking of mutual exclusion semaphores is possible. This means that a task that holds before finally releasing a semaphore, can take the semaphore more than once.
- Options for making the task which takes as DELETE_SAFE are provided by Mutex, which means the task deletion is not possible when holding the mutex.
What is a semaphore?A semaphore is hardware or a software tag variable whose value indicates the status of a common resource. Its purpose is to lock the resource being used. A process which needs the resource will check the semaphore for determining the status of the resource followed by the decision for proceeding. In multitasking operating systems, the activities are synchronized by using the semaphore techniques.