Jose Marcio Martins da Cruz
8/5/2004 1:44:00 PM
Hello,
I bad explained...
igor@notformail.paco.net wrote:
> Jose Marcio Martins da Cruz <martins@paris.ensmp.fr> wrote:
>>
>>When the worker finishes with the task, it shall return to file
>>descriptor to the "poller" thread in order to put it again at the array
>>of pollfd data. I do this with a pipe(2) : to awake the poll call, I
>>write to one end - the other end is one of the file descriptors on the
>>array of pollfd data.
>
>
> I'm not sure if this is best way. IMHO the better solution is not to pass
> control over socket to worker thread (of cource, if if you can do all the
> job in the context of polling thread). Then you will not need to introduce
> unneeded context switches, you don't need to write to pipe (as you can be
> sure that polling thread is not hang in the poll/select at the moment you
> operate on the socket).
>
No, in fact each fd is part of a context. Workers are blocked in a
pthread_cond_wait call. When the controler gets an event on a file
descriptor, it changes the state of the corresponding context and signal
the workers. One of the workers will handle the task.
>
>>So, the poll call is waiting on :
>>
>>- The worker writes one character on the write end of the pipe;
>>- The poll call returns with the correct pipe file descriptor.
>
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> How this
>
>
>>- the contents of "events" member of the data returned is the same value
>>I put before the call (POLLIN | POLLPRI)
>>- the contents of "revents" member of the data returned is "0" - no event ???
>
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> correspond with this?
>
> Do you really check events on the pipe descriptor?
>
Let me give a more explicit example :
I set up a pipe, and the read end of the pipe is one of the fds the poll
is looking at.
When a worker ends his job, it needs to awake the poll call in order to
put the fd he was working on, be included again on the set of file
descriptors the controler is looking at.
So, he writes one character at the write end of the pipe, in order to
awake the controler. The poll call at the controler returns the data
corresponding to the read end of the pipe. Eg.
fd 13 correct
events POLLIN | POLLPRI correct
revents 0 ??????
I don't understand how revents can be 0.... And if I try to read this
file descriptor, the read call gets blocked.
If I use select instead of poll, all this works fine. ...
But I don't want to use select, as at some moment, the value of the file
descriptor can be greater than FD_SETSIZE.