diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-03-02 21:20:28 -0800 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-03-02 22:44:36 -0800 |
commit | 19668b0edc9b09cfd72247f7041390e0328032a0 (patch) | |
tree | f2d0d7bb08612cb597ec684705ee0c7957df76f3 | |
parent | 0f4a8ef81479f9eff9037011d81b96cf402cbe7b (diff) | |
download | ruby_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.
-rw-r--r-- | lib/posix_mq.rb | 3 |
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/ |