Created
December 6, 2019 14:10
-
-
Save anhnguyen1618/64dddffd019fde4b49ab2f439ee90eec 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 Capacity = N | |
| Semaphore hasItem = 0 | |
| Semaphore mutex = 1 | |
| Semaphore mutex_out = 1 | |
| Producer { | |
| while (True) { | |
| item = produce() | |
| Capacity.acquire() | |
| mutex.acquire() | |
| in = (in + 1) mod N | |
| buffer[in] = item | |
| mutex.release() | |
| hasItem.release() | |
| } | |
| } | |
| Consumer { | |
| while(True) { | |
| hasItem.acquire() | |
| mutex_out.acquire() | |
| out = (out + 1) mod N | |
| item = buffer[out] | |
| mutex_out.release() | |
| Capacity.release() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment