apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Querna <c...@force-elite.com>
Subject Re: some question about apr pollset
Date Thu, 15 Dec 2005 08:11:05 GMT
[Adding CC to dev@apr]

tingya wrote:
> Paul Querna:
>      Hi, I read your description about epoll apr_pollset_t,especially  those three ring:query_ring,free_ring
and dead_ring.
> in _add():  
> - If there is an extra pollfd in the free_ring, reuse it.  
> - If not, palloc() one.  
>  
> in _remove():  
> - Move the pollfd from the query_ring to the dead_ring  
>  
> in _poll():  
> - After polling is complete, move any pollfds inside the dead_ring to  
> the free_ring, as it is safe to re-use them now.  
>  
> 
> The dead_ring is used to save all the nodes which were moved from query_ring. My question
is if I can don't use the dead_ring,just leave two ring:query_ring and free_ring. so all these
became:
>  in _add():  
> - If there is an extra pollfd in the free_ring, reuse it.  
> - If not, palloc() one.  
>  
> in _remove():  
> - Move the pollfd from the query_ring to the free_ring??
> 

In the future, the best place to discuss this is the APR Dev Mailing list:
http://apr.apache.org/mailing-lists.html


The dead_ring is used to prevent a race condition.  When _remove is
called, and the socket is removed from the epoll(), another thread might
already be inside apr_pollset_poll().  This the result set returned from
poll() could contain a recently _remove()'ed socket.  If this pollfd was
re-used without a dead_ring, it would be possible that we wouldn't have
a pollfd to associate with a socket in the result set.

One could argue, that if it was removed, we really really don't went to
see it again, and therefore we should err to the other side of this race
condition, and remove it possibly too early.


At least, this is what I remember of the reasons behind it at midnight
after getting off a plane. :)

-Paul

Mime
View raw message