From: john@peppermind.com
Subject: How do I get an enctry in a protected object to block until a certain item arrives from a producer task?
Date: Tue, 23 Aug 2016 10:15:44 -0700 (PDT)
Date: 2016-08-23T10:15:44-07:00 [thread overview]
Message-ID: <b72fe101-8630-4114-a8a8-6f82e323605b@googlegroups.com> (raw)
Hi! I've also asked this on Stackoverflow because I'm really stuck with this. I have a protected object that contains an ordered hash map. It stored events by their id as they are provided by some producer task. Now one or more consumer tasks can obtain these events, but I need a call that blocks the consumer until a given id has arrived while the producer continues producing. So a simple barrier doesn't work.
I can't find a directly applicable design pattern in my Ada books for this, although I imagine this is some kind of FAQ.
Here is the relevant code snippet:
package Reply_Storage is new Ada.Containers.Indefinite_Ordered_Maps
(Key_Type => Command_Id_Type,
Element_Type => Event_Type);
protected type Reply_Queue is
procedure Put (Event : Event_Type);
entry Take (Id : Command_Id_Type; Event : out Event_Type);
private
Storage : Reply_Storage.Map;
end Reply_Queue;
protected body Reply_Queue is
procedure Put (Event : Event_Type) is
Id : Command_Id_Type := Event_Command_Id (Event);
begin
Storage.Insert (Id, Event);
end Put;
entry Take (Id : Command_Id_Type; Event : out Event_Type)
when not Storage.Is_Empty is
begin
if Storage.Contains(Id) then
Event := Storage.Element (Id);
Storage.Delete (Id);
end if;
end Take;
end Reply_Queue;
Basically, instead of not Storage.Is_Empty, I'd not the condition Storage.Contains(Id). The consumer should block until the map has received the event with the given id. But I don't know how. :/
next reply other threads:[~2016-08-23 17:15 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-23 17:15 john [this message]
2016-08-23 17:52 ` How do I get an enctry in a protected object to block until a certain item arrives from a producer task? Egil H H
2016-08-23 19:26 ` J-P. Rosen
2016-08-23 20:02 ` Jeffrey R. Carter
2016-08-23 19:44 ` Dmitry A. Kazakov
2016-08-24 9:49 ` Mark Lorenzen
2016-08-24 10:26 ` Dmitry A. Kazakov
2016-08-23 21:34 ` Some Dude
2016-08-23 22:28 ` Jeffrey R. Carter
2016-08-23 21:37 ` Some Dude
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox