Subject: Re: select call implementation and threads
To: Bill Studenmund <wrstuden@netbsd.org>
From: malleswararao venkatanaga <bobbyavn@yahoo.com>
List: tech-kern
Date: 05/28/2003 10:07:32
Hi Andrey and Bill,
 I've tested my code with PTL (Portable Thread
Library) and it doesnot give me any problems. Both the
selects break and both the threads handle the
messages.
 So I guess it the pthread library that is having some
problem of scheduling the threads. 

thanks


--- Bill Studenmund <wrstuden@netbsd.org> wrote:
> On Sun, 25 May 2003, malleswararao venkatanaga
> wrote:
> 
> > --- Andrey Petrov <petrov@netbsd.org> wrote:
> > > On Sat, May 24, 2003 at 04:26:11AM -0700,
> > > malleswararao venkatanaga wrote:
> > > > Here is the code i tested with.
> > > > /* Recv.c This is the code that receives
> messages
> > > */
> > > > #include <stdio.h>
> > > > #include<fcntl.h>
> > > > #include<errno.h>
> > > > #include<sys/types.h>
> > > > #include<sys/select.h>
> > > > #include<sys/socket.h>
> > > > #include<netinet/in.h>
> > > > #include <pthread.h>
> > > >
> > > > void * stub_test (void *p );
> > > > pthread_t  threads[3];
> > > > int main()
> > > > {
> > > >   int rc;
> > > >   stub_test2();
> > > >   rc = pthread_create(&threads[0], NULL ,
> > > stub_test
> > > > ,(void *) &threads[0]);
> > >
> > > Well, well, well. Try to reverse 2 previous
> lines.
> > >
> > Hi Andrey,
> > I've reversed the above 2 lines. But i still get
> > non-deterministic results, one of the threads gets
> > blocked and never comes out of the select call
> though
> > it has messages to read.
> >
> > Probably there is something to do with the
> scheduling
> > of the threads as the thread which is receiving
> and
> > processing the messages is never yielding the
> other
> > thread is never getting a chance to run through
> its
> > steps and break out of the select call.
> > Surprisingly the thread which gets blocked in the
> > select call should have actually tried to yield to
> > the others which is not happening.
> 
> No, it actually is yielding. 1.6 doesn't have
> kernel-assisted pthreads. To
  It must be yielding but I guess there is some thing
wrong with the pthread library that it doesnot
schedule the other thread.

> the kernel there is only one thread. So the fact
> that one or the other
> runs means that there is some yielding going on.
> 
> I think the key problem is that you're trying to
> have two simultaneous
> select calls going on. Since to the kernel there is
> only one thread, there
> can only be one select going on at once.
> 
> For what you want to have happen to work, the
> userland thread package has
> to help. It has to consolidate both selects into
> one.
> 

> Take care,
> 
> Bill
> 


__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com