comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: How to: communication between multiple tasks using protected objects - with no polling?
Date: Tue, 20 Jan 2015 17:47:26 -0700
Date: 2015-01-20T17:47:26-07:00	[thread overview]
Message-ID: <m9msu0$hja$2@dont-email.me> (raw)
In-Reply-To: <32208488-3a04-4d2a-8c64-840502dcf96d@googlegroups.com>

On 01/20/2015 03:36 PM, Esa Riihonen wrote:
> 
> The C-program consists of various Linux processes that communicate with each
> other mainly through FIFO's. It seems natural to implement the process
> functionality as Ada tasks.  As the inter task communication I decided to try
> protected types (instead of task entries).

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.

> Am I missing something? Or have my though processes been totally corrupted by
> too much (forced) C during the decades - and thus I'm trying to do something
> silly and dangerous?

You can do

select
   PO1.Get (...);
then abort
   PO2.Get (...);
end select;

This might, however, result in both entries being executed.

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;

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.

-- 
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

  parent reply	other threads:[~2015-01-21  0:47 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 [this message]
2015-01-21  8:11   ` Simon Wright
2015-01-21 17:16   ` Esa Riihonen
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