Subject: Re: interrupting kevent()
To: Antti Kantee <>
From: Bill Stouder-Studenmund <>
List: tech-kern
Date: 10/24/2007 22:52:51
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Tue, Oct 23, 2007 at 03:45:49PM +0300, Antti Kantee wrote:
> Hi,
> I have a dual eventloop/thread model and I need to interrupt the event
> call from a thread sometimes.  I didn't find any sensible way of doing
> this, so I added a KEVENT_TICKLE ioctl() to kqueue for interrupting
> the wait.

The canonical way I know to do this is to create a pipe and add a kevent
to listen to it. That way you get what you want w/o any kernel mods. Plus,
if you use an atomic write (everything in one write{,v}() call), then you
can use the write to the pipe as a form of ITC (Inter-Thread
Communication) - not only do you wake the thread, but you carry the
message w/o needing locks on the sending side.

The concern/objection I have to what you do have is that it doesn't follow=
kevent methodology. I think your kevent should show up as an event. As it=
stands, you only get an event if there is nothing else going on, and it=20
shows up out-of-band with the events. A busy server could delay=20
conveying the "tickle" for a few system calls.

Also, the canonical event handler style I've seen for kevent code is you
look at the cookie in the event, and it's a pointer to either the handler
routine or to a structure containing the event handler.

So I'd like to politely ask you to go back to the drawing board. While I=20
think something other than a pipe could be cute, I think we should do=20
something that will work in more cases than just your current one.

Take care,


Content-Type: application/pgp-signature
Content-Disposition: inline

Version: GnuPG v1.4.7 (NetBSD)