comp.lang.ada
 help / color / mirror / Atom feed
From: "Michal Morawski" <morawski@zsk.p.lodz.pl>
Subject: Re: Suspicious reentrant semaphore
Date: Mon, 5 May 2003 13:24:56 +0200
Date: 2003-05-05T13:24:56+02:00	[thread overview]
Message-ID: <b95ia2$lfp$1@atlantis.news.tpi.pl> (raw)
In-Reply-To: b8t6ik$d4egi$1@ID-77047.news.dfncis.de

Does it works in GNAT?

I have written the following program, which cannot be compiled because the
construction "then abort" is not understand by the compiler.

I expect the result:
**..
**..
....
....
Am I right?


with Ada.Text_IO;                         use Ada.Text_IO;

procedure Ins_Requeue is

   protected I is
      entry E1 (X, Y : Integer);
      entry E2 (X, Y : Integer);
      entry E3;
   private
      E1_X, E1_Y,
      E2_X, E2_Y : Integer;
   end I;

   protected body I is
      entry E1 (X, Y : Integer) when True is
      begin
         E1_X := X;
         E1_Y := Y;
         requeue E3 then abort;
************^^ Here is error
      end E1;

      entry E2 (X, Y : Integer) when True is
      begin
         E2_X := X;
         E2_Y := Y;
         requeue E3 then abort;
      end E2;

      entry E3 when E1_X < E2_X and E1_Y < E2_Y is
      begin
         Put ('*');
      end E3;
   end I;

begin
   I.E1 (3, 3);
   for x in 1 .. 4 loop
      for y in 1 .. 4 loop
         select
            I.E2 (x, y);
         else
            Put ('.');
         end select;
      end loop;
      New_Line;
   end loop;
end Ins_Requeue;


-- 
Michal Morawski

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
news:b8t6ik$d4egi$1@ID-77047.news.dfncis.de...
> Jano wrote:
>
> > Dmitry A. Kazakov dice...
> >> The requeue statement does the trick in case you want to use a
parameter
> >> value in a barrier. You could add one more private entry and requeue to
> >> it if the task is not the owner:
> >
> > Dmitry: I love this suggestion specially because is the first time I'm
> > going to employ requeue (never before I faced the necessity).
>
> It is one of the most interesting things added to Ada 95!
>
> > Here is the new version of my package. I've also slightly changed the
> > release logic to obtain exceptions instead of deadlocks in case of wrong
> > use:
>
> You can also get rid of the task-id parameter, as Randy Brukardt has
> suggested. Sort of:
>
> entry P when true is
> begin
>    if Owner = P'Caller then
>       In_use := In_use + 1;
>    else
>       requeue Safe_P with abort;
>    end if;
> end P;
>
> entry Safe_P when In_use = 0 is
> begin
>    Owner := Safe_P'Caller;
>    In_use := 1;
> end Safe_P;
>
> procedure V is
> begin
>    if Owner /= Current_Task then
>       raise Use_error;
>    else
>       In_use:= In_use - 1;
>       if In_use = 0 then
>          Owner := Null_task_id;
>       end if;
>    end if;
> end V;
>
> -- 
> Regards,
> Dmitry A. Kazakov
> www.dmitry-kazakov.de





  parent reply	other threads:[~2003-05-05 11:24 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-29 22:04 Suspicious reentrant semaphore Jano
2003-04-30  8:06 ` Dmitry A. Kazakov
2003-05-01 12:33   ` Jano
2003-05-02  7:28     ` Dmitry A. Kazakov
2003-05-02 11:24       ` Jano
2003-05-02 20:29         ` tmoran
2003-05-05 11:24       ` Michal Morawski [this message]
2003-05-05 17:42         ` Simon Wright
2003-05-05 18:03         ` Jano
2003-05-05 20:18           ` Micha� Morawski
2003-04-30 13:07 ` Ian Broster
2003-05-01 12:33   ` Jano
2003-04-30 17:39 ` Randy Brukardt
2003-04-30 23:21   ` Peter Richtmyer
2003-05-01  4:59     ` Simon Wright
2003-05-01 12:46   ` Jano
replies disabled

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