Homework-5 曾治历 Version 0 |
|
👤 Author: by tsangzlfoxmailcom 2018-10-28 03:33:46 |
A semaphore is a counter that is used to handle synchronization problems of processes or threads, especially for synchronous access to critical resources.
Critical resources can be simply understood as resources that can only be operated by one process or thread at a time, where resources
It can be a code, a variable, or some kind of hardware resource. When the value of semaphore is greater than or equal to 0, it can be used by concurrent processes.
The number of resource entities; less than 0 represents the number of processes that are waiting for the use of critical resources.
Semaphore operation
The semaphore value is related to the usage of the corresponding resource. When its value is greater than 0, it indicates the number of resources currently available, and when its value is less than 0, its absolute value indicates the number of processes waiting to use the resource. The value of semaphore can only be changed by PV operation.