Operating System: The driver and conductor of the synchronization process

The driver and conductor of the synchronization process

     On the bus driver and conductor workflow as shown in FIG.

     To ensure the safety of passengers, drivers and conductors should work in close cooperation and coordination.

     Please to achieve synchronization between the driver and the conductor with a semaphore.

     The driver put the vehicle normal traffic station parking

     Conductor shut the door car door ticket

     Figure drivers and conductors work flow chart

 

 

Not snatch the resources in this problem, so no mutexes.

Driver and conductor are synchronized relationship, whether the driver needs to receive good semaphore door shut, and the amount of the conductor needs to receive signals arriving from the car is.
The sequence of activities: Off the door -> start the vehicle -> Ticket -> station parking -> car door
initial state: parking and the door is not closed.
Process: conductor close to the driver's signal, the driver began to receive normal running of the vehicle, when the station by the driver to stop the signal conductor.
Solution: semaphore is set close Door = 0 , the semaphore to stop stop = 0.

 

 

 


void Driver(){
     while(1){
       wait(door);//司机等待关门信号,一旦获取信号,则启动车辆
       启动车辆;
       正常行车;
       到站停车;
       signal(stop); //司机给售票员停车的信号
     }
}
void Busman(){
     while(1){
       关车门;
       signal(door);  //售票员给司机已经关门的信号
       售票;
       wait(stop);    //等待停车信号,一旦停车,则开门
       开车门;
} 












 

 

Published 736 original articles · won praise 123 · views 80000 +

Guess you like

Origin blog.csdn.net/S_999999/article/details/103676543