Created
December 7, 2019 11:51
-
-
Save anhnguyen1618/c55de3b5a26549aaa8c0a48b9aafe12d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Semaphore[] forks = {1, 1, 1, 1, 1} | |
| eat(i) { | |
| left= (i + 4) % 5 | |
| right = (i + 1) % 5 | |
| if (i == 5) { | |
| forks[right].acquire() | |
| forks[left].acquire() | |
| eat() | |
| forks[right].release() | |
| forks[left].release() | |
| return; | |
| } | |
| forks[left].acquire() | |
| forls[right].acquire() | |
| eat() | |
| forks[right].release() | |
| forks[left].release() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment