Skip to content

Instantly share code, notes, and snippets.

@mrnkr
Created December 3, 2018 00:48
Show Gist options
  • Save mrnkr/4aa3ed66f1c78fa13e08a9f16bc81c60 to your computer and use it in GitHub Desktop.
Save mrnkr/4aa3ed66f1c78fa13e08a9f16bc81c60 to your computer and use it in GitHub Desktop.
Philosophers: Array 0..4 of Philosopher;
task type Philosopher is
end
task body Philosopher is
begin
loop
Table.Enter
Chopsticks.Request
Chopsticks.Request
Eat
Chopsticks.Release
Chopsticks.Release
Table.Leave
end loop
end Philosopher;
task Chopsticks is
entry Request;
entry Release;
end
task body Chopsticks is
Remaining: Int := 5;
begin
loop
select
when Remaining > 0 accept Request;
Remaining := Remaining - 1;
or
accept Release;
Remaining := Remaining + 1;
end select
end loop
end Chopsticks;
task Table is
entry Enter;
entry Leave;
end
task body Table is
Remaining_Space: Int := 4;
begin
loop
select
when Remaining_Space > 0 accept Enter
Remaining_Space := Remaining_Space - 1;
or
accept Leave
Remaining_Space := Remaining_Space + 1;
end select
end loop
end Table;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment