Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- If the train driver from Peru is asking to use the pass then they will state their interest by placing a stone in the basket. If the train driver from Bolivia is interested too then to get out of the deadlock it is automatically set to the Bolivian trains turn, the Peru train driver removes his stone from the basket. Once the Bolivian train driver has left the pass and taken his stone out of the basket, then the Peruvian train driver puts his stone back in to the basket and goes through the pass. Once the Peruvian train has left the pass the driver removes his stone from the basket.
- While(true) {
- Peru train driver put stone in basket
- While(Bolivia train driver has stone in basket)
- {
- If it is Bolivia trains turn to use the pass
- {
- Peru train takes stone out of basket
- While(it is Bolivia trains turn)
- Wait
- Peru Train driver puts stone in basket
- }
- }
- Turn = Bolivia Train Driver
- Peru train driver takes stone out of basket
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement