This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: waking a thread that's in select()?
On Thu, Sep 28, 2000 at 11:43:10AM -0500, Grant Edwards wrote:
> > > I've got a thread that is doing a select() on a set of sockets
> > > (waiting for incoming TCP requests). Is there a way for
> > > another thread to wake-up the select()ing thread?
> >
> > There is a function to break select out. Have a look at the end of
> > packanges/net/tcpip/current/src/lib/select.c.
>
> I can't get it to work.
After some additional debugging, I've discovered that when I
call cyg_select_abort(), it never sets any bits in select_flag
because it thinks nobody is waiting on select_flag. And yet,
my thread never returns from cyg_select_with_abort().
The call to cyg_select_abort() is being made from within a web
server task which is also calling select. If I move the call
to cyg_select_abort() to a different thread, then my thread
_does_ wake up when it's supposed to.
My theory is that the following sequence of events is taking
place:
1) My task calls cyg_select_with_abort(), which waits on
select_flag
2) Web server task calls select(), which also waits on
select_flag
3) TCP/IP connection wakes up both my task and the web server
from the flag_wait they called on select flag.
(at this point, no tasks are waiting on select_flag)
4) Web server task runs, sees I/O is waiting, returns from
select(), [some other stuff] calls cyg_select_abort().
cyg_select_abort() sees that nobody is waiting on
select_flag, and assumes that means there are no select()s
to abort, so it doesn't set any bits in select_flag.
Web server task finishes and blocks (probably on select()).
5) My task runs, sees that there is no I/O ready, and the
ABORT flag wasn't set, so goes back to sleep on
select_flag with flag_wait.
I'm going to try to fix this by making my task a higher
priority than the web server task, so that it goes back to
sleep on select_flag _before_ the web server calls
cyg_select_abort().
--
Grant Edwards
grante@visi.com