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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,UTF8 Path: g2news2.google.com!postnews.google.com!j19g2000vbp.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: Ada and (SIGTERM?) Date: Sat, 8 Aug 2009 08:06:23 -0700 (PDT) Organization: http://groups.google.com Message-ID: <52dab4e5-9ee0-4e01-9072-32a95caadb84@j19g2000vbp.googlegroups.com> References: <42c9446c-76d2-4c82-abab-fd7c5573d85e@k30g2000yqf.googlegroups.com> <4244cbe7-1655-484b-a376-0237802ab37d@p10g2000prm.googlegroups.com> <103641e8-0738-4b10-b2c6-cbfb53b50d98@d34g2000vbm.googlegroups.com> NNTP-Posting-Host: 85.1.147.180 Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1249743983 28676 127.0.0.1 (8 Aug 2009 15:06:23 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 8 Aug 2009 15:06:23 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: j19g2000vbp.googlegroups.com; posting-host=85.1.147.180; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.13) Gecko/2009073021 Firefox/3.0.13,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:7661 Date: 2009-08-08T08:06:23-07:00 List-Id: On 8 Sie, 15:11, Tomek Wa=C5=82kuski wrote: > I cannot stop task if Do_Something is Accept_Socket from GNAT.Sockets. > > There is a listener which waits for client connections and then > delegates jobs to the worker tasks. I want to stop all tasks and > finalize all objects when SIGTERM is fired. Use non-blocking I/O and a selector to wait for the sockets to become ready. You might need to set up a separate pair of sockets (one for writing and one for reading - a socket-based implementation of a simple pipe) which you can use to break out of the selector. This solution is very scalable and can handle any number of listeners and regular sockets in a single construct. If you want to preserve the blocking I/O scheme in your program, you can break out of Accept_Socket by establishing an artificial connection to the listening socket. Just pretend to be your own client and knock to your own door. :-) When the Accept_Socket returns, check the "quit" flag to decide what to do next. This flag should be set before establishing this artificial connection to yourself, so that it is already set up when Accept_Socket returns. -- Maciej Sobczak * www.msobczak.com * www.inspirel.com Database Access Library for Ada: www.inspirel.com/soci-ada