Homework5 Version 0 |
|
👤 Author: by 1035256715qqcom 2018-10-29 02:20:06 |
Question:
explain semaphore's operation.
Answer:
A semaphore is a variable or abstract data type used to control access to a common resource by multiple processes in a concurrent system such as a multitasking operating system. A semaphore is simply a variable. This variable is used to solve critical section problems and to achieve process synchronization in the multi processing environment. A trivial semaphore is a plain vairable that is changed (for example, incremented or decremented, or toggled) depending on programmer-defined condition.
Semaphore are a useful tool in the prevention of race conditions; however, their use is by no means a guarantee that a program is free from these problems. Semaphores which allow an arbitrary resource count are called counting semaphores, while semaphores which are restricted to the values 0 and 1 (locked/unlocked, unavailable/available) are called binary semaphores and are used to implement locks.