Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

kqueue-based pselect

10 views
Skip to first unread message

William Ahern

unread,
Sep 22, 2012, 9:02:17 PM9/22/12
to
pselect is broken on OS X* and NetBSD 5.1**, and OpenBSD doesn't bother
trying to implement the interface. I think I've come up with a race-free
user land implementation using kqueue. From my notes:

A kqueue-portable implementation of pselect:

1) install EVFILT_SIGNAL for the signal set currently blocked but
soon to be unblocked
2) check sigpending for such signal set
3) install requested signal mask
4) call select with kqueue descriptor added to the read fd_set
5) restore signal mask
6) check return values from select and kqueue

Non-obviousness:

o Any other signal set than described above could be lost even with
a kernel pselect. An implementation could elect to minimize the
race condition, but that would merely postpone the inevitable.

o EVFILT_SIGNAL is edge triggered, so it won't catch pending signals
delivered upon unblocking, thus the necessity to call sigpending
after kevent, but before sigprocmask/pthread_sigmask.

o The above scheme is susceptiple to spurious wakeup, e.g. by
SIG_IGN handlers which wouldn't interrupt a kernel pselect.

Can anybody find any holes?


* OS X implements a silly wrapper around select and is fundamentally broken.
** NetBSD 5.1 has a bug where it interrupts, but doesn't actually deliver
the signal.

0 new messages