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-Thread: 103376,7322e496af76698c X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!d4g2000prg.googlegroups.com!not-for-mail From: gpriv@axonx.com Newsgroups: comp.lang.ada Subject: Re: Ada Thread Termination Date: Sat, 2 Feb 2008 13:23:34 -0800 (PST) Organization: http://groups.google.com Message-ID: <23f424ed-dc0f-453a-bb8b-e1edfe31d2a8@d4g2000prg.googlegroups.com> References: NNTP-Posting-Host: 151.196.71.114 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1201987414 26994 127.0.0.1 (2 Feb 2008 21:23:34 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 2 Feb 2008 21:23:34 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: d4g2000prg.googlegroups.com; posting-host=151.196.71.114; posting-account=YaY8rAoAAAAAnFXOECY3BGVJsrvFJCgy User-Agent: G2/1.0 X-HTTP-Via: 1.1 SPARKS X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:19691 Date: 2008-02-02T13:23:34-08:00 List-Id: 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