Subject: Re: interrupting kevent()
To: None <tech-kern@NetBSD.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-kern
Date: 10/23/2007 11:50:14
>>> 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.
>> Other ideas: use socketpair() or pthread_kill(thread, SIGIO).
> I considered writing to a socket, but couldn't figure out how to do
> it without having to drain the signal byte from the socket therefore
> taking two syscalls for signalling instead of one.

If the receiving thread is blocking waiting for events, why is it a
problem for it to do one more syscall?  If you're doing that much
cross-thread signaling, perhaps you need to revisit how tasks are
allocated between threads?

(Actually, to be pedantic, you can avoid the signal byte by closing, or
doing a shutdown on, the other side - but that means even more syscalls
to return to the original state, so it doesn't help with the big
problem even though it solves the stated small problem.)

/~\ The ASCII				der Mouse
\ / Ribbon Campaign
 X  Against HTML	       mouse@rodents.montreal.qc.ca
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B