Created
December 3, 2018 00:49
-
-
Save mrnkr/6865499b45698b5421cab8b4bdbd92d0 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 Buffer is | |
entry Insert (In_Val: in T); | |
entry Extract (Out_Val: out T); | |
end | |
task body Buffer is | |
Data: Array 0..N-1 of Int; | |
Top: Int; | |
Bottom: Int; | |
Length: Int; | |
x: T; | |
begin | |
loop | |
select | |
when Length < N accept Insert (In_Val: in Int) do | |
Datos[Top] := In_Val; | |
end; | |
Top := (Top + 1) mod N; | |
Length := Length + 1; | |
or | |
when Length > 0 accept Extract (Out_Val: out Int) do | |
Out_Val := Data[Bottom]; | |
end; | |
Bottom := (Bottom + 1) mod N; | |
Length := Length - 1; | |
end select | |
end loop | |
end Buffer; | |
task type Producer is | |
end | |
task body Producer is | |
Produced: T; | |
begin | |
loop | |
Produce(Produced); | |
Buffer.Insert(Produced); | |
end loop | |
end Producer; | |
task type Consumer is | |
end | |
task body Consumer is | |
Consumed: T; | |
begin | |
loop | |
Buffer.Extract(Consumed); | |
Consume(Consumed); | |
end loop | |
end Consumer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment