Homework 5 Version 0 |
|
👤 Author: by 804824950qqcom 2020-11-03 06:50:50 |
Use the record semaphore to solve the following problems, and write the process synchronization algorithm in C-like language.
Driver P1 Conductor P2
REPEAT REPEAT
Start close
Normal operation
Stop and open the door
UNTIL FALSE UNTIL FALSE
semaphore s1,s2;
s1=0; //door
s2=0; //Car
P1() //driver
{
wait(s1);
start up
Normal driving
Arrival
signal(s2);
}
P2()//The conductor
{
close the door;
signal(s1);
Ticket sales
wait(s2);
Open the door;
}