From 19668b0edc9b09cfd72247f7041390e0328032a0 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 2 Mar 2010 21:20:28 -0800 Subject: 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. --- lib/posix_mq.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib') 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/ -- cgit v1.2.3-24-ge0c7