comp.lang.ada
 help / color / mirror / Atom feed
From: gpriv@axonx.com
Subject: Re: Ada Thread Termination
Date: Sat, 2 Feb 2008 13:23:34 -0800 (PST)
Date: 2008-02-02T13:23:34-08:00	[thread overview]
Message-ID: <23f424ed-dc0f-453a-bb8b-e1edfe31d2a8@d4g2000prg.googlegroups.com> (raw)
In-Reply-To: f7866882-e806-46a6-a97e-a33bdf042338@e10g2000prf.googlegroups.com

On Feb 2, 2:41 pm, shaunpatter...@gmail.com wrote:
> I have a socket listening thread that I would like to be able to
> terminate via a select call.
>
> task body Socket_Listener is
>   begin
>      accept Initialize do
>            -- setup
>      end Initialize;
>
>      loop
>            Listen_For_Message;
>      end loop;
>   end Socket_Listener
>
> I would like to have another accept statement inside the loop to break
> out of the loop.
>
> Listen_For_Message is actually a call to a blocking socket read, so
> the call may not finish if nothing else comes through the socket. I'm
> not sure how to structure this thread so it can be terminated on
> demand.
>
> Any ideas?
>
> Thanks
>
> --
> Shaun

In addition to what Dmintry has suggested you may consider setting
receive timeout when opening the socket.

task body socket_listener is
begin
    select
       accept initialize ...
    or
       terminate;
    end select;

    while socket_is_open loop

       select
          accept close_connection do
              gracefully close socket here
          end close_connection
       else
          listen_for_message_ignore_timeouts...
       end select;

    end loop;

end socket_listener;

be aware that there is a bug in windows: socket timeouts are
interpreted in milliseconds

Regards,

George Privalov



  parent reply	other threads:[~2008-02-02 21:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-02 19:41 Ada Thread Termination shaunpatterson
2008-02-02 19:55 ` Dmitry A. Kazakov
2008-02-02 21:23 ` gpriv [this message]
2008-02-04 17:57 ` Adam Beneschan
2008-02-04 23:26   ` Robert A Duff
replies disabled

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