Skip to content

Instantly share code, notes, and snippets.

@mrnkr
Created December 3, 2018 00:50
Show Gist options
  • Select an option

  • Save mrnkr/62f3d98c169a8c01d5d6a96370d77817 to your computer and use it in GitHub Desktop.

Select an option

Save mrnkr/62f3d98c169a8c01d5d6a96370d77817 to your computer and use it in GitHub Desktop.
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