Fri 31 Jul 2009 06:39:28 PM UTC, comment #6:
Hi Aymeric,
I'm sorry, but I don't see how using select() helps in the matter. I must be missing something in your API.
When I read that code (the same goes for _wait, by the way), what I see is a race between the thread that produces events and the one that consumes them.
What is supposed to happen if between the time select() returns and the time you do the read, an event is posted on the pipe?
Your read() call will return 2 of those "w", but the caller of _get/_wait will only ever see one event, because those functions only return one event. Unless of course the caller is supposed to check some "next" field in the eXosip_event_t structure, but that would open a locking can of worms.
There is actually another race in _wait: the first call to select() seems to be used to purge the pipe so if a new event was posted between the call to osip_fifo_tryget(), you lose it and you'll have to wait for the timeout in case nothing else comes before.
What I expect in _get/_wait is for them to only ever block if there's truly nothing more in the queue. I don't see how that can happen in the current code. Unless, as I said, there is a way for the user to purge the queue by themselves before going back to _get/_wait, but not only this would be highly surprising as far as _get/_wait APIs go, but I don't see anything in the documentation indicating there is such a way anyway.
Sorry it took me so long to reply.
Quentin Garnier.
|