From: Esa Riihonen <esa.riihonen.er@gmail.com>
Subject: Re: How to: communication between multiple tasks using protected objects - with no polling?
Date: Wed, 21 Jan 2015 09:16:03 -0800 (PST)
Date: 2015-01-21T09:16:03-08:00 [thread overview]
Message-ID: <cd097f9b-3610-4456-a903-676ad9c2ef9f@googlegroups.com> (raw)
In-Reply-To: <m9msu0$hja$2@dont-email.me>
keskiviikko 21. tammikuuta 2015 2.47.29 UTC+2 Jeffrey Carter kirjoitti:
... snip ...
> You should also revisit your design in light of Ada tasking capabilities. The
> choice of multiple tasks that communicate through queues may not be the best choice.
That is totally correct.
... snip ...
> You can do
>
> select
> PO1.Get (...);
> then abort
> PO2.Get (...);
> end select;
>
> This might, however, result in both entries being executed.
If I understand correctly this will indeed work when selecting between two PO entries. And it wouldn't matter if both got executed (although I just now can't see how this could happen). However, there seems not to be a natural way to expand this for more than those two. This seems to be syntactically correct (compiles):
select
PO1.Get (...);
then abort
select
PO2.Get (...);
then abort
PO3.Get (...);
end select
end select;
But I'm not sure whether it would actually do what I want it to do. That is: suspend there until any of the entry barriers becomes true and then exit the whole outermost select statement?
Even if it works I have a (minor) concern that it is not 'pretty' as it doesn't reflect the mutual equality of the entries - and thus has a feel of 'hack' there ;)
> Another approach might be
>
> type Q_ID is (Q1, Q2, ...);
>
> type Q_Item (Q : Q_ID := Q_ID'First) is record
> case Q is
> when Q1 =>
> Item_1 : Q1_Item;
> when Q2 =>
> Item_2 : Q2:Item;
> ...
> end case;
> end record;
>
> protected Qs is
> entry Get (Item : out Q_Item);
> private -- Qs
> Q_1 : Q1_Q;
> Q_2 : Q2_Q;
> ...
> end Qs;
>
> protected body Qs is
> entry Get (Item : out Q_Item) when
> not Q_1.Is_Empty or not Q_2.Is_Empty or ...
> is
> -- Empty declarative part
> begin -- Get
> if not Q_1.Is_Empty then
> Item := (Q => Q1, Item_1 => Q_1.Get);
> elsif not Q_2.Is_Empty then
> item := (Q => Q2, Item_2 => Q_2.Get;
> ...
> end if;
> end Get;
> end Qs;
Thanks for that! I'm not sure I did understand it thoroughly at first reading though I did say that I did read 'the book' - but surely it didn't all sink in in the first reading ;)
> if your system is actually many tasks adding items to queues and one waiting for
> something on one of those queues, then it might be best to have the waiting task
> have entries, and put forwarder tasks between the queues and the waiting task.
'Forwarder tasks' - definitely might be something I will study at this stage.
Thanks a lot.
> --
> Jeff Carter
> "Ada has made you lazy and careless. You can write programs in C that
> are just as safe by the simple application of super-human diligence."
> E. Robert Tisdale
> 72
I really like the Tisdale quote - gonna steal it ;)
next prev parent reply other threads:[~2015-01-21 17:16 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-20 22:36 How to: communication between multiple tasks using protected objects - with no polling? Esa Riihonen
2015-01-21 0:19 ` Hubert
2015-01-21 16:53 ` Esa Riihonen
2015-01-21 23:22 ` Hubert
2015-01-22 13:24 ` Esa Riihonen
2015-01-21 0:47 ` Jeffrey Carter
2015-01-21 8:11 ` Simon Wright
2015-01-21 17:16 ` Esa Riihonen [this message]
2015-01-21 18:39 ` Jeffrey Carter
2015-01-22 13:32 ` Esa Riihonen
2015-01-21 8:28 ` Dmitry A. Kazakov
2015-01-21 17:34 ` Esa Riihonen
2015-01-21 18:56 ` Jacob Sparre Andersen
2015-01-21 20:15 ` Dmitry A. Kazakov
2015-01-22 21:52 ` G.B.
2015-01-23 8:25 ` Dmitry A. Kazakov
2015-01-21 20:02 ` Dmitry A. Kazakov
2015-01-22 13:37 ` Esa Riihonen
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox