Subject: Re: select call implementation and threads
To: malleswararao venkatanaga <>
From: Bill Studenmund <>
List: tech-kern
Date: 05/24/2003 16:44:04
On Sat, 24 May 2003, Andrey Petrov wrote:

> On Fri, May 23, 2003 at 09:50:02AM -0700, malleswararao venkatanaga wrote:
> > Hi,
> >  I'm facing a problem and it is somewhat like this,
> >   1)I spawn a thread using pthread_create()
> >   2) In the thread I open a socket, bind it to a port
> > say 10001 and block it in the select call for
> > receiving a UDP message.
> >   Similarly
> >   In my main thread i open a socket and bind it to a
> > port say 10000 and block the main thread in a select
> > call.
> >   Both the main thread and the other thread are
> > essentially waiting for different messages on
> > different ports and different socket fds with their
> > respective select calls.
> >   I observe that if i send a messages to both of them
> > only one of them receives while the other one is still
> > blocked in the select call though it has messages to
> > read.

Sounds like a bug in pth. It should either be merging both select calls
into one in the kernel, or it should at least be re-starting one of them
when the other finishes.

I think a better way to handle this case is have one thread sleep on
select (on both file descriptors), and have two worker threads ready to do
what you want to have happen after the select. When the select() thread
sees something, it wakes one or the other worker thread.

Take care,