public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Anton Titov <a.titov@host.bg>
To: "Li, Peng" <ringer9cs@gmail.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: Thread safety for epoll/libaio
Date: Wed, 01 Mar 2006 03:55:42 +0200	[thread overview]
Message-ID: <1141178142.7208.12.camel@localhost> (raw)
In-Reply-To: <598a055d0602281236m7eac9c09oc60af9ce28e7e4bf@mail.gmail.com>

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.




  reply	other threads:[~2006-03-01  1:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-28 20:36 Thread safety for epoll/libaio Li, Peng
2006-03-01  1:55 ` Anton Titov [this message]
2006-03-01  2:27 ` Benjamin LaHaise
2006-03-01  3:35 ` Phillip Susi
2006-03-01  3:48 ` David Schwartz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1141178142.7208.12.camel@localhost \
    --to=a.titov@host.bg \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ringer9cs@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox