From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,78546269947cb927 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-03-30 03:45:57 PST Path: archiver1.google.com!news1.google.com!news.glorb.com!news.tele.dk!news.tele.dk!small.news.tele.dk!news-FFM2.ecrc.net!news.iks-jena.de!not-for-mail From: Lutz Donnerhacke Newsgroups: comp.lang.ada Subject: Re: Combining entry_call, accept_statment and terminate_statment Date: Tue, 30 Mar 2004 11:45:57 +0000 (UTC) Organization: IKS GmbH Jena Message-ID: References: <106h7clrs4iio8c@corp.supernews.com> NNTP-Posting-Host: taranis.iks-jena.de X-Trace: branwen.iks-jena.de 1080647157 32359 217.17.192.37 (30 Mar 2004 11:45:57 GMT) X-Complaints-To: usenet@iks-jena.de NNTP-Posting-Date: Tue, 30 Mar 2004 11:45:57 +0000 (UTC) User-Agent: slrn/0.9.8.0 (Linux) Xref: archiver1.google.com comp.lang.ada:6669 Date: 2004-03-30T11:45:57+00:00 List-Id: * 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.