Subject: Re: scheduler activations problem ?
To: Gary Duzan <gary@duzan.org>
From: Nathan J. Williams <nathanw@wasabisystems.com>
List: current-users
Date: 10/20/2003 08:59:10
Gary Duzan <gary@duzan.org> writes:
> In Message <200310201439.13439.kefren@netbastards.org> ,
> Mihai CHELARU <kefren@netbastards.org> wrote:
>
> => for(;;) {
> => FD_ZERO(&fs);
> => FD_SET(s, &fs);
> => select(s + 1, &fs, NULL, NULL, NULL);
>
> Try checking the return value of this select() call for errors.
>
> => if (pthread_create(&pt, NULL, persocket, (void *) (&s)))
> => perror("pthread_create");
> => if (pthread_detach(pt))
> => perror("pthread_detach");
> =>// pth_yield(NULL);
> => }
Additionally, you aren't guaranteed that the new thread will run
before this thread loops around again and creates more threads - it
looks like that's what the pth_yield() was trying to do in the
original code, but trying to use scheduling and luck for
synchronization doesn't work very well. Since nothing in *this* loop
touches the file descriptor s, select() will continue to return the
same status. You need some kind of handoff mechanism so that you only
create one thread at a time per connection.
- Nathan