Message from discussion Interruption of select()
Subject: Re: Interruption of select()
References: <firstname.lastname@example.org> <email@example.com> <firstname.lastname@example.org>
From: sbu...@dev0.welkyn.com (Sean P. Burke)
User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2
Content-Type: text/plain; charset=iso-8859-1
X-Trace: newssvr13.news.prodigy.com 1044639658 ST000 18.104.22.168 (Fri, 07 Feb 2003 12:40:58 EST)
NNTP-Posting-Date: Fri, 07 Feb 2003 12:40:58 EST
Organization: Prodigy Internet http://www.prodigy.com
Date: Fri, 07 Feb 2003 17:40:58 GMT
"Petr Pecka" <petr.pe...@ima.cz> writes:
> "Sean P. Burke" <sbu...@dev0.welkyn.com> píse v diskusním príspevku
> > "Petr Pecka" <petr.pe...@ima.cz> writes:
> > > Hi,
> > >
> > > I have a mutlithreaded communication application where several threads
> > > in select() for an UDP packet. The select() returns only when packet is
> > > received or timeout expires. I need to be able to interrupt this
> > > immediately and do other processing when some event occurs in another
> > > thread. The select() timeout can be quite long (1 sec or so) and I don't
> > > want to decrease it and check continuously if the event occured or not.
> > > These events won't occur very often, but if they occur, I need immediate
> > > reaction in the communicatin thread.
> > >
> > > In Win32 it can be implemented using events and I can wait for UDP
> packet or
> > > event in one call, or I can assign event to socket using
> > > Any advice how to implement this on Linux and pthreads?
> > >
> > > I can see these possibilities:
> > > 1. using SIGURS1 or SIGUSR2 to interrupt select() but there can are
> > > several identical threads waiting in select() and I need to interrupt
> > > one of them. It is also discuraged to use signals with pthreads.
> > > 2. opening unix-domain datagram socket for each thread and make the
> > > select() wait on both of these sockets. The event thec can be signaled
> > > sending some data on this unix-domain socket.
> > > 3. the same could be probably done with pipes.
> > On Unix, I usually use solution 3, but I would like to know
> > how to do this on WIN32. Do you use select() on WIN32, or
> > WaitForMultipleObjects()?
> > -SEan
> On Win32 I use WaitForMultipleObejcts() or WSAWaitForMultipleEvents(). It
> should be more efficient than using pipes and select(), at least I hope so.
It has to be - the pipe/select technique does not work
at all on windows. The select call ignores the pipe fd.
Some windows calls look like their posix counterparts,
but this is a trap for the unwary.