comp.lang.ada
 help / color / mirror / Atom feed
From: Some Dude <john@peppermind.com>
Subject: Rendezvous with select ... else and "or terminate" not possible - but how do I quit this task?
Date: Thu, 1 Sep 2016 08:43:50 -0700 (PDT)
Date: 2016-09-01T08:43:50-07:00	[thread overview]
Message-ID: <6e4d6fc1-dcb9-454a-8c1e-df090224438e@googlegroups.com> (raw)

I have a task with entries Start, Stop, Send, Close and an else clause that does some main processing when none of the entries are processed. So the structure is (very simplified):

task body Connection_Handler is
      Done : Boolean := False;
   begin
      accept Start (Socket : Socket_Type) do
        -- do this first 
      end Start;
      loop
         select when not Done =>
            accept Stop do
               Done := True;
            end Stop;
         or when not Done =>
            accept Send (Socket : Socket_Type; Command : Command_Type) do
               -- do something
            end Send;
         or when not Done =>
            accept Close (Socket : Socket_Type) do
               -- do something
               end Close;
         else
            if not Done then
               -- receive data if necessary using GNAT.sockets.Check_Selector
               -- while no data is sent
            end if;
         end select;
         exit when Done;
      end loop;
   end Connection_Handler;

However, when Stop is called and Done set to True, I get 

  raised TASKING_ERROR : s-tasren.adb:445

as an exception in my AUnit test harness and the test ends prematurely with an error code. This occurs in the main program task, or at least if I add a catch-all exception handler in the above task body, it is *not* triggered there.

I thought this occurs perhaps because there is no terminate alternative, but if I add:
 
   or terminate;

before the else part, I get the error message "else part not allowed with other alternatives". So this is not possible.

Is there a way to stop the task gracefully (without abort) but also do some continuous processing like in the else part? Does anybody have an idea what might cause this error?


             reply	other threads:[~2016-09-01 15:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-01 15:43 Some Dude [this message]
2016-09-01 16:05 ` Rendezvous with select ... else and "or terminate" not possible - but how do I quit this task? J-P. Rosen
2016-09-01 16:10 ` Dmitry A. Kazakov
2016-09-01 21:30 ` Some Dude
replies disabled

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