Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964803AbWCABzp (ORCPT ); Tue, 28 Feb 2006 20:55:45 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S964804AbWCABzp (ORCPT ); Tue, 28 Feb 2006 20:55:45 -0500 Received: from mail.host.bg ([87.120.40.5]:3264 "EHLO mail.host.bg") by vger.kernel.org with ESMTP id S964803AbWCABzo (ORCPT ); Tue, 28 Feb 2006 20:55:44 -0500 Subject: Re: Thread safety for epoll/libaio From: Anton Titov To: "Li, Peng" Cc: Linux Kernel Mailing List In-Reply-To: <598a055d0602281236m7eac9c09oc60af9ce28e7e4bf@mail.gmail.com> References: <598a055d0602281236m7eac9c09oc60af9ce28e7e4bf@mail.gmail.com> Content-Type: text/plain Organization: Host.bg Date: Wed, 01 Mar 2006 03:55:42 +0200 Message-Id: <1141178142.7208.12.camel@localhost> Mime-Version: 1.0 X-Mailer: Evolution 2.4.2.1 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1298 Lines: 36 On Tue, 2006-02-28 at 15:36 -0500, Li, Peng wrote: > Thread B: while(1) { epoll_wait(); ... } > // same as thread A > Thread D: ... epoll_ctl(); .... > > Suppose thread B calls epoll_wait and blocks before thread D calls > epoll_ctl. Is it safe to do so? Will thread B be notified for the > event submitted by thread D? Hello, I have some (more) expirience with epoll and threads and it seem to work well. If you have epoll_wait() in one thread and another thread do epoll_ctl to add a handle, epoll_wait will wake up as soon as the handle is ready for operation (most of the time instantly, when operation is write). epoll man page states: Q6 Will the close of an fd cause it to be removed from all epoll sets automatically? A6 Yes. but I was experiencing some (rare) segfaults with my application while benchmarking it when I just closing my descriptors. Debugging showed, that I'm getting events for destroyed objects (with closed descriptors). Adding epoll_ctl(..., EPOLL_CTL_DEL, ...) fixed this. - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/