comp.lang.ada
 help / color / mirror / Atom feed
* How to: communication between multiple tasks using protected objects - with no polling?
@ 2015-01-20 22:36 Esa Riihonen
  2015-01-21  0:19 ` Hubert
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Esa Riihonen @ 2015-01-20 22:36 UTC (permalink / raw)



I'm new to Ada and I have a problem ;)

After reading through 'Programming in ADA 2012' by John Barnes - I decided to try Ada in implementing the core functionality of a C-program I have been involved recently.

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

Here is the problem. My typical C-process 'listens' to several FIFOs connected to separate processes. This is realized using a ppoll-type 'reactor' - so in essence the process is sleeping until there is some activity in any of the monitored file descriptors (I guess this is in essence quite basic arrangement in the 'C-world').

I first thought I can implement this by the 'select' - something like this:

PO1 and PO2 are instantiations of a protected type with entry 'Get'.

...
loop
  ...
  select
    PO1.Get(...);
  or
    PO2.Get(...);
  or 
    ...
  end select;
  ...
end loop;
...

Alas, I quicky found out that 'or' is not allowed here between the protected object entries.

I can do something like this instead:

...
loop
  ...
  select
    PO1.Get(...);
  else
    null;
  end select;

  select
    PO2.Get(...);
  else
    null;
  end select;
  ...
end loop;
...

But this would be now constantly polling in a loop. I would like the task to be suspended if there is nothing to do. I understand(?) that I probably could achieve this by accepting task entries. But I wan't to know whether it can be done using the protected objects for communication. 

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?


^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2015-01-23  8:25 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox