LWN.net Logo

EPOLL_CTL_DISABLE and multithreaded applications

EPOLL_CTL_DISABLE and multithreaded applications

Posted Oct 19, 2012 12:41 UTC (Fri) by pbonzini (subscriber, #60935)
In reply to: EPOLL_CTL_DISABLE and multithreaded applications by mhelsley
Parent article: EPOLL_CTL_DISABLE and multithreaded applications

That pretty much boils down to delaying the deletion of the items to a moment where all epoll_waits have been done (since epoll_wait is an RCU quiescence point).

An efficient solution for an arbitrary number of epoll_wait threads can be implemented even in userspace and without using a full-blown RCU.

Equip each thread with a) an id or something else that lets each thread refer to "the next" thread; b) a lists of "items waiting to be deleted". Then the deleting thread adds the item being deleted to the first thread's list. Before executing epoll_wait, thread K empties its list and "passes the buck", appending the old contents of its list to that of thread K+1. This is an O(1) operation no matter how many items are being deleted; only Thread N, being the last thread, actually has to go through the list and delete the items.


(Log in to post comments)

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds