ALL > Computer and Education > courses > university courses > undergraduate courses > Operating System > ZSTU-(2020-2021)-1 > student homework > 2018329621213_黄冰慧 >
homework06_2018329621213 Version 0
👤 Author: by 454234624qqcom 2020-11-07 08:26:09
Semaphores: is a non-negative integer. All threads / processes passing through it will reduce the integer by one (through it, of course, to use resources). When the integer value is zero, all threads trying to pass through it will be in a waiting state. In terms of semaphores, we define two operations: wait and signal.

When a thread calls the wait operation, it either gets the resource and decrements the semaphore by one, or waits until the semaphore is greater than or equal to one. Release is actually an addition operation on the semaphore. This operation is called "release" because it releases the resources guarded by the semaphore.

The definition of wait() is as follows:



The definition of signal() is as follows:



All the modifications to the integer value of the semaphore in the wait() and signal() operations must be executed indivisibly. That is, when one process modifies the semaphore value, no other process can simultaneously modify that same semaphore value. In addition, in the case of wait(S), the testing of the integer value of s (s ≤ 0), and its possible modification (S--), must also be executed without interruption.

Example: A factory has a warehouse that can store equipment, a total of 10 equipment can be stored. Each production equipment must be put into storage, and the sales department can provide the equipment to customers from the warehouse. The equipment must be put into and out of the warehouse by means of transportation. At present, there is only one transport vehicle, and only one equipment can be transported at a time. Please design an automatic scheduling management system that can coordinate work.

Solution:  S is mutex initialized to 1.



 

Please login to reply. Login

Reversion History

Loading...
No reversions found.