Last active
July 6, 2019 08:27
-
-
Save TommyWu-fdgkhdkgh/fa35fad354811a1241270657d028421e 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 mutex = 1; | |
| int next_count = 0;//等待next的個數 | |
| semaphore next = 0; | |
| int x_count = 0;//等待x_sem的個數 | |
| semaphore x_sem = 0; | |
| /* monitor */ | |
| /* monitor start */ | |
| wait(mutex); | |
| ... | |
| body of F | |
| ... | |
| if(next_count > 0){ | |
| signal(next); | |
| }else { | |
| signal(mutex); | |
| } | |
| /* monitor end */ | |
| /* condition variable wait, x.wait() */ | |
| x_count++; | |
| if(next_count > 0){ | |
| signal(next); | |
| }else { | |
| signal(mutex); | |
| } | |
| wait(x_sem); | |
| x_count--; | |
| /* condition variable signal, x.signal() */ | |
| if(x_count > 0){ | |
| next_count++; | |
| signal(x_sem); | |
| wait(next); | |
| next_count--; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment