From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.98.22.149 with SMTP id 143mr21208813pfw.10.1471972544354; Tue, 23 Aug 2016 10:15:44 -0700 (PDT) X-Received: by 10.157.9.106 with SMTP id 97mr1565326otp.7.1471972544310; Tue, 23 Aug 2016 10:15:44 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!f6no12338004ith.0!news-out.google.com!d130ni44526ith.0!nntp.google.com!f6no12361790ith.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 23 Aug 2016 10:15:44 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2001:8a0:6a4f:fe01:d8f1:ac77:fb4c:e02c; posting-account=nd46uAkAAAB2IU3eJoKQE6q_ACEyvPP_ NNTP-Posting-Host: 2001:8a0:6a4f:fe01:d8f1:ac77:fb4c:e02c User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: How do I get an enctry in a protected object to block until a certain item arrives from a producer task? From: john@peppermind.com Injection-Date: Tue, 23 Aug 2016 17:15:44 +0000 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:31519 Date: 2016-08-23T10:15:44-07:00 List-Id: Hi! I've also asked this on Stackoverflow because I'm really stuck with thi= s. I have a protected object that contains an ordered hash map. It stored e= vents by their id as they are provided by some producer task. Now one or mo= re consumer tasks can obtain these events, but I need a call that blocks th= e consumer until a given id has arrived while the producer continues produc= ing. 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 =3D> Command_Id_Type, Element_Type =3D> 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 :=3D 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 :=3D 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.C= ontains(Id). The consumer should block until the map has received the event= with the given id. But I don't know how. :/