[ECOS] Wake select() with a signal

Nick Garnett nickg@ecoscentric.com
Thu Nov 7 15:14:00 GMT 2002


Roland Caßebohm <roland.cassebohm@visionsystems.de> writes:

> On Mittwoch, 6. November 2002 18:13, Nick Garnett wrote:
> > In Unix I suppose one way of fixing this would have been to add a pipe
> > to the set of read FDs and have the other thread write to that to wake
> > the select() -- you probably don't need to use a signal at all. We do
> > not have pipes in eCos, but a loop-back TCP socket would probably do
> > the same thing.
> >
> > The POSIX-200X standard has added a pselect() call, which takes an
> > additional signal mask argument, specifically to allow this race
> > condition to be eliminated.
> 
> You are right, this will be a general problem for me. Till now I never had the 
> race condition if the signal comes just before calling select(), but I think 
> this is only, because my application waits most of the time in the select().
> To be sure that my application work always, I have to use one of the solutions 
> you have written.
> 
> I'm thinking of implementing a pselect() call. Where should this function be 
> located, in packages/compat/posix or in packages/io/fileio?
> 

It should go in the FILEIO package. The best approach would be to
convert the current select() into pselect() and then add a new
select() that just calls pselect() with a NULL sigmask argument. And
pselect() takes a struct timespec rather than a struct timeval for the
timeout, so that would have to be converted too. Here are the
declarations for comparison:

int pselect(int nfds, fd_set *readfds, fd_set *writefds,
        fd_set *errorfds, const struct timespec *timeout,
        const sigset_t *sigmask);

int select(int nfds, fd_set *restrict readfds,
        fd_set *restrict writefds, fd_set *restrict errorfds,
        struct timeval *restrict timeout);

As for where to set the new mask, that is a bit more complex. Simply
calling pthread_sigmask() is not the right thing to do. And the code
in select() would need some restructuring.

Hmm, this is not looking as simple as it did when I started this
message. I'll need to think about this a while. In the meantime you
may want to investigate the socket option.


-- 
Nick Garnett - eCos Kernel Architect
http://www.eCosCentric.com/

--
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss



More information about the Ecos-discuss mailing list