POSIX_MQ#notify block execution on message received
commit40d61f55ac53e3cd2f229d0b032da03032e3d53d
authorEric Wong <normalperson@yhbt.net>
Thu, 7 Jan 2010 08:37:57 +0000 (7 00:37 -0800)
committerEric Wong <normalperson@yhbt.net>
Thu, 7 Jan 2010 09:15:05 +0000 (7 01:15 -0800)
tree4c57be5ba0dd0a9f1dff33bada0635188848e50b
parentd8c8fb4155c1feea454abc3ed3f0a4b26e90be68
POSIX_MQ#notify block execution on message received

This is implementation uses both a short-lived POSIX thread and
a pre-spawned Ruby Thread in a manner that works properly under
both Ruby 1.8 (green threads) and 1.9 (where Ruby Threads are
POSIX threads).

The short-lived POSIX thread will write a single "\0" byte to
a pipe the Ruby Thread waits on.  This operation is atomic
on all platforms.  Once the Ruby Thread is woken up from the
pipe, it will execute th block given to it.

This dual-thread implementation is inspired by the way glibc
implements mq_notify(3) + SIGEV_THREAD under Linux where the
kernel itself cannot directly spawn POSIX threads.
README
ext/posix_mq/extconf.rb
ext/posix_mq/posix_mq.c
lib/posix_mq.rb
test/test_posix_mq.rb