comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: 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 21:44:20 +0200
Date: 2016-08-23T21:44:20+02:00	[thread overview]
Message-ID: <npi92n$mpc$1@gioia.aioe.org> (raw)
In-Reply-To: b72fe101-8630-4114-a8a8-6f82e323605b@googlegroups.com

On 2016-08-23 19:15, john@peppermind.com wrote:
> 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.

The universal pattern for this I call the "lounge pattern". It allows 
waiting for some condition that cannot be evaluated as a barrier or 
requires too many different entries (a large family of entries).

Examples are waiting for a combination of events or for a specific real 
value or set of values, etc.

The idea is as follows. You have the original entry with the parameter 
that is used to evaluate the condition ending waiting. The entry has no 
barrier. Then you have two private entries with the same parameter or a 
family of entries parametrized by Boolean, these are the "lounge". The 
lounge entries have the barrier that is True for one and False for another.

You call the public entry. Within it you evaluate the condition. If 
satisfied you are done. If not you requeue to the lounge entry that is 
currently closed.

You toggle barriers of the lounge entries when it makes sense to 
reevaluate a condition. That opens the closed lounge entry. In the entry 
you evaluate the condition using the parameter. Again if not satisfied 
you requeue to another entry and keep on waiting.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

  parent reply	other threads:[~2016-08-23 19:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-23 17:15 How do I get an enctry in a protected object to block until a certain item arrives from a producer task? john
2016-08-23 17:52 ` 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 [this message]
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