comp.lang.ada
 help / color / mirror / Atom feed
From: Lutz Donnerhacke <lutz@iks-jena.de>
Subject: Re: Combining entry_call, accept_statment and terminate_statment
Date: Tue, 30 Mar 2004 11:45:57 +0000 (UTC)
Date: 2004-03-30T11:45:57+00:00	[thread overview]
Message-ID: <slrnc6infl.o5.lutz@taranis.iks-jena.de> (raw)
In-Reply-To: slrnc6i8dt.o5.lutz@taranis.iks-jena.de

* Lutz Donnerhacke wrote:
> In order to prevent polling, I implemented a second protected type
> (constrainted with an anonymous access to the ringbuffer) to encapsulate
> the reader position variable and use it for an entry barrier on this
> second type.

Polling is not necessary. It's important to transfer caller information into
the entry_barrier, and this can be done using an entry family:

package PT is
   subtype Index is Integer range 1 .. 5;

   protected type T is
      procedure Set(x : Integer);
      entry Get(Index)(x : out Integer);
   private
      p : Integer := 0;
   end T;
end PT;
      
package body PT is
   protected body T is
      procedure Set(x : Integer) is
      begin
         p := x;
      end Set;
      
      entry Get(for i in Index)(x : out Integer) when p >= i is
      begin
         x := p;
      end Get;
   end T;
end PT;

with Ada.Text_IO; use Ada.Text_IO;
with PT;

procedure test_pt is
   test : PT.T;
   
   task type TT is
      entry Name(c : Character);
   end TT;

   task body TT is
      n : Character;
      i : Integer;
      d : PT.Index;
   begin
      accept Name(c : Character) do
         n := c;
      end Name;

      d := Character'Pos(n) - Character'Pos('a');
      Put_Line(n & ": Uses index" & d'Img);

      loop
         delay 0.1;
         Put_Line(n & ": Reading");
         test.Get(d)(i);
         Put_Line(n & ": Got" & i'Img);
         exit when i > d;
      end loop;
      Put_Line(n & ": Exit");
   end TT;

   t : array(Character'('a') .. 'f') of TT;
begin
   for i in t'Range loop
      Put_Line("Naming " & i);
      t(i).Name(i);
   end loop;

   for i in Integer range 0 .. 10 loop
      delay 0.25;
      Put_Line("Setting" & i'Img);
      test.Set(i);
   end loop;
end test_pt;

Please do not blame me for calling Ada.Text_IO.Put_Line without
synchronisation.



  parent reply	other threads:[~2004-03-30 11:45 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-29 19:41 Combining entry_call, accept_statment and terminate_statment Lutz Donnerhacke
2004-03-29 22:04 ` Randy Brukardt
2004-03-29 23:19   ` Mark Lorenzen
2004-03-29 23:14     ` Robert I. Eachus
2004-03-30  7:26   ` Lutz Donnerhacke
2004-03-30 20:04     ` Randy Brukardt
2004-03-30 22:47       ` Lutz Donnerhacke
2004-03-31  9:03         ` Dmitry A. Kazakov
2004-03-31  9:14           ` Lutz Donnerhacke
2004-03-31 12:22             ` Dmitry A. Kazakov
2004-03-31  6:39       ` Jean-Pierre Rosen
2004-03-30  7:29   ` Lutz Donnerhacke
2004-03-30  8:11     ` tmoran
2004-03-30 11:45     ` Lutz Donnerhacke [this message]
2004-03-30  0:33 ` James Rogers
replies disabled

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