ALL > Computer and Education > courses > university courses > undergraduate courses > Operating System > ZSTU class(2019-2020-1) > student directories > 2017329600011_曾文哲 >
homework-4 Version 0
👤 Author: by vanjiazenggmailcom 2019-09-29 03:37:30
During the National Day, the number of express delivery increases, and the courier company needs to set up some additional warehouses to store goods.
Suppose each warehouse has two workers. One of them can store goods into warehouse, another can moving the goods out of the warehous.
Good can only be moving out when stock is not empty. Good can only be storing when stock is not full.

Solution:
Set two semaphores S and C, the initial value is S=0; C=0;
Name the worker who can store goods into warehouse with the name Woker_1.
Name the worker who can moving the goods out of the warehous with name Worker_2.
Worker_1:                                        Worker_2:
Loop1:Storing                                            Loop2: moving

①Goods arrived                                           ① P(S)

②V(S)                                                       ②Stock is not empty. Move out goods

③P(C)                                                       ③Goods leaving

④Stock is not full. Store goods                 ④V(C)

Please login to reply. Login

Reversion History

Loading...
No reversions found.