Created
December 3, 2018 00:50
-
-
Save mrnkr/62f3d98c169a8c01d5d6a96370d77817 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
| task type Semaphore is | |
| entry Init (Initial_Capacity: in Int); | |
| entry Wait; | |
| entry Signal; | |
| end | |
| task body Semaphore is | |
| Remaining_Capacity: Int; | |
| begin | |
| accept Init (Initial_Capacity: in Int) do | |
| Remaining_Capacity := Initial_Capacity; | |
| end | |
| loop | |
| select | |
| when Remaining_Capacity > 0 accept Wait; | |
| Remaining_Capacity := Remaining_Capacity - 1; | |
| or | |
| accept Signal; | |
| Remaining_Capacity := Remaining_Capacity + 1; | |
| end select | |
| end loop | |
| end Semaphore; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment