Backport #5342
closedConditionVariable can wake a Thread that is no longer waiting on it
Description
See gist at https://gist.github.com/1228184 for a reproducible test case.
Sequence is like this:
- Main thread spawns Thread 1. Thread 1 pauses 0.5 seconds and then signals cond variable 1.
- Main thread waits on cond variable 1 and times out after 0.3 seconds
- Main thread spawns Thread 2. Thread 2 pauses 0.5 seconds and then signals cond variable 2.
- Main thread waits on cond variable 2 with a timeout of 1.0 seconds.
I would expect this test to take 0.8 seconds. Instead the main thread is woken by the original cond variable 1 after 0.5 seconds total.
The code works as expected on JRuby 1.6.4.
Updated by normalperson (Eric Wong) over 12 years ago
Mike Perham mperham@gmail.com wrote:
ruby -v: ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]
See gist at https://gist.github.com/1228184 for a reproducible test case.
I can confirm the test case fails on 1.9.2-p290 on x86_32 Linux, too.
ruby_1_9_3 r33290 appears good, however. The GVL was reimplemented for
1.9.3 to improve fairness and performance, so there are likely bugs
fixed along the way.
Updated by kosaki (Motohiro KOSAKI) over 12 years ago
- Tracker changed from Bug to Backport
- Project changed from Ruby master to Backport192
- Status changed from Open to Assigned
- Assignee set to yugui (Yuki Sonoda)
Updated by kosaki (Motohiro KOSAKI) over 12 years ago
Hi
2011/9/20 Eric Wong normalperson@yhbt.net:
Mike Perham mperham@gmail.com wrote:
ruby -v: ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.8.0]
See gist at https://gist.github.com/1228184 for a reproducible test case.
I can confirm the test case fails on 1.9.2-p290 on x86_32 Linux, too.
ruby_1_9_3 r33290 appears good, however. Â The GVL was reimplemented for
1.9.3 to improve fairness and performance, so there are likely bugs
fixed along the way.
The bug was fixed by following commit. (r27711)
It haven't backported 1.9.2 yet.
commit f4053cf5554deb0051aabfc90180784236f1f25b
Author: mame mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Date: Sun May 9 17:10:18 2010 +0000
* lib/thread.rb (ConditionVariable#wait): ensure to remove the current
thread from waiters. [ruby-core:29835]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27711
b2dd03c8-39d4-4d8f-98ff-823fe69b080e
diff --git a/ChangeLog b/ChangeLog
index 7677a70..91c0e41 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon May 10 02:07:20 2010 Yusuke Endoh mame@tsg.ne.jp
+
-
* lib/thread.rb (ConditionVariable#wait): ensure to remove the current
-
thread from waiters. [ruby-core:29835]
Mon May 10 00:54:15 2010 Nobuyoshi Nakada nobu@ruby-lang.org
* ext/io/console/console.c (console_set_raw): new method.
diff --git a/lib/thread.rb b/lib/thread.rb
index f3831a7..88f834c 100644
--- a/lib/thread.rb
+++ b/lib/thread.rb
@@ -69,6 +69,10 @@ class ConditionVariable
@waiters.push(Thread.current)
end
mutex.sleep timeout
- ensure
-
@waiters_mutex.synchronize do
-
@waiters.delete(Thread.current)
-
endend
self
end
Updated by naruse (Yui NARUSE) almost 8 years ago
- Status changed from Assigned to Rejected