about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-03-02 21:20:28 -0800
committerEric Wong <normalperson@yhbt.net>2010-03-02 22:44:36 -0800
commit19668b0edc9b09cfd72247f7041390e0328032a0 (patch)
treef2d0d7bb08612cb597ec684705ee0c7957df76f3 /lib
parent0f4a8ef81479f9eff9037011d81b96cf402cbe7b (diff)
downloadruby_posix_mq-19668b0edc9b09cfd72247f7041390e0328032a0.tar.gz
fix potential race with notify(&block)
We need to assign the notify_thread before assigning the
notification.  Otherwise, there's a chance the notification
could fire and the notify_thread is not properly assigned for
the POSIX_MQ object when the pipe becomes readable.
Diffstat (limited to 'lib')
-rw-r--r--lib/posix_mq.rb3
1 files changed, 1 insertions, 2 deletions
diff --git a/lib/posix_mq.rb b/lib/posix_mq.rb
index 86fa67e..33b54f4 100644
--- a/lib/posix_mq.rb
+++ b/lib/posix_mq.rb
@@ -47,7 +47,7 @@ class POSIX_MQ
     block.arity == 1 or
       raise ArgumentError, "arity of notify block must be 1"
     r, w = IO.pipe
-    thr = Thread.new(r, w, self) do |r, w, mq|
+    self.notify_thread = Thread.new(r, w, self) do |r, w, mq|
       begin
         begin
           r.read(1) or raise Errno::EINTR
@@ -62,7 +62,6 @@ class POSIX_MQ
       end
     end
     self.notify = w
-    self.notify_thread = thr
     nil
   end if RUBY_PLATFORM =~ /linux/