From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10650a,aa6f820f3f67c7ef X-Google-Attributes: gid10650a,public X-Google-Thread: fa528,aa6f820f3f67c7ef X-Google-Attributes: gidfa528,public X-Google-Thread: 115614,aa6f820f3f67c7ef X-Google-Attributes: gid115614,public X-Google-Thread: fcda7,aa6f820f3f67c7ef X-Google-Attributes: gidfcda7,public X-Google-Thread: 11035d,aa6f820f3f67c7ef X-Google-Attributes: gid11035d,public X-Google-ArrivalTime: 2001-04-13 03:46:17 PST Path: supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!newsfeed.stanford.edu!paloalto-snf1.gtei.net!news.gtei.net!news.compaq.com!news.cpqcorp.net!not-for-mail Message-ID: <3AD6D8C2.62C0C704@compaq.com> From: Dave Butenhof X-Mailer: Mozilla 4.77 [en] (X11; U; OSF1 V5.0 alpha) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.unix.internals,comp.unix.solaris,comp.unix.tru64,comp.sys.hp.hpux,comp.unix.aix Subject: Re: awaking a thread ... waiting on select or poll References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Fri, 13 Apr 2001 06:45:22 -0400 NNTP-Posting-Host: 16.31.48.112 X-Complaints-To: abuse@Compaq.com X-Trace: news.cpqcorp.net 987158722 16.31.48.112 (Fri, 13 Apr 2001 03:45:22 PDT) NNTP-Posting-Date: Fri, 13 Apr 2001 03:45:22 PDT Organization: Compaq Computer Corporation Xref: supernews.google.com comp.unix.internals:491 comp.unix.solaris:38110 comp.unix.tru64:2117 comp.sys.hp.hpux:8696 comp.unix.aix:14824 MrSignor wrote: > Is there a reliable way (across Unix platforms) to wake-up a thread > sleeping/waiting on a Select or Poll, that is not timing out the request. > > Basically, I have a thread, waiting for work on 1-n sockets. Upon > occassion, I would like to wake the sleeping-thread, because I > need to bring something to it's attention. Given "pthread_t Target;", use "pthread_kill(Target,SIGUSR1)"... or whatever other signal seems appropriate. (Beware that on Linux, the thread implementation uses SIGUSR1 itself.) Use a signal that you can distinguish from "real signals". (E.g., don't use SIGSEGV, or SIGCHLD.) Of course, you need to know the pthread_t value of the thread. That must be recorded either by the creator or the thread itself using pthread_self(). This'll work for any syscall that can return EINTR. The call site can of course detect the interruption by looking for -1 and EINTR return. Normally, the signal action for the chosen signal should be set as an empty routine (just returns). If more than one thread might want to do this, you might consider a "time server" that allows individual threads to get alarm()-like behavior without interfering with each other. You call some API that queues a wakeup request, and a separate server thread zaps each registered thread at the appropriate time. One example package is in the thread utilities library from Bil Lewis' book Multithreaded Programming with Pthreads; his examples are available online from http://www.LambdaCS.com. /------------------[ David.Butenhof@compaq.com ]------------------\ | Compaq Computer Corporation POSIX Thread Architect | | My book: http://www.awl.com/cseng/titles/0-201-63392-2/ | \-----[ http://home.earthlink.net/~anneart/family/dave.html ]-----/