concurrent interface Bounded_BufferTo wait on a Get from two different buffers, you could do this using the select statement in ParaSail:
<Element_Type is Assignable<>;
Index_Type is Integer<>> is
function Create_Buffer(
Max_In_Buffer : Index_Type {Max_In_Buffer > 0})
-> Result : Bounded_Buffer;
// Create buffer of given capacity
procedure Put(Buffer : queued Bounded_Buffer;
Element : Element_Type);
// Add element to bounded buffer;
// remain queued until there is room
// in the buffer.
function Get(Buffer : queued Bounded_Buffer)
-> Element_Type;
// Retrieve next element from bounded buffer;
// remain queued until there is an element.
end interface Bounded_Buffer;
selectA select statement attempts to perform each of the queued operations concurrently. The first one to become dequeued causes the others to be canceled, and then proceeds to completion.
var X := Get(Buf1) => ... // use X received from Buf1
||
var X := Get(Buf2) => ... // use X received from Buf2
end select;
Time delays are also represented as queued operations on a concurrent object (a clock or a timer):
concurrent interface Clock<Time_Type is Assignable<>>Presumably a call of Delay_Until(C, Wakeup_Time) will queue the caller until Now >= Wakeup_Time. A possible implementation of the Delay_Until procedure could use that as its dequeue condition:
is
function Create_Clock(...) -> Clock;
function Now(C : locked Clock) -> Time_Type;
procedure Delay_Until
(C : queued Clock; Wakeup : Time_Type);
end interface Clock;
concurrent class Clock<Time_Type is Assignable<>>We can effectively put a time bound on a select statement by adding an alternative that is a call on an operation like Delay_Until:
is
var Current_Time : Time_Type;
...
exports
...
function Now(C : locked Clock) -> Time_Type is
return Current_Time;
end Now;
procedure Delay_Until
(C : queued Clock; Wakeup : Time_Type)
queued until Current_Time >= Wakeup is
return; // nothing more to do
end Delay_Until;
...
end class Clock;
select
var X := Get(Buf1) => ...
||
var X := Get(Buf2) => ...
||
Delay_Until(Next_Time) => ...
end select;
No comments:
Post a Comment