summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--ext/thread/thread.c3
-rw-r--r--test/thread/test_thread.rb38
-rw-r--r--version.h2
4 files changed, 49 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 75702855f1..3364b098c2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Mon Sep 17 05:24:13 2007 Sylvain Joyeux <sylvain.joyeux@m4x.org>
+
+ * ext/thread/thread.c (lock_mutex): should take care of threads
+ not waiting any longer; there cases of a thread raising
+ exceptions. [ ruby-Bugs-11901 ]
+
+ * test/thread/test_thread.rb (test_mutex_exception_handling):
+ test for above.
+
Mon Sep 17 05:01:55 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* runruby.rb: fix incomplete backport r12339.
diff --git a/ext/thread/thread.c b/ext/thread/thread.c
index 43dfc348ed..3dba9ba32a 100644
--- a/ext/thread/thread.c
+++ b/ext/thread/thread.c
@@ -422,9 +422,8 @@ lock_mutex(Mutex *mutex)
mutex->owner = current;
}
else {
- push_list(&mutex->waiting, current);
do {
- rb_thread_stop();
+ wait_list(&mutex->waiting);
rb_thread_critical = 1;
if (!MUTEX_LOCKED_P(mutex)) {
mutex->owner = current;
diff --git a/test/thread/test_thread.rb b/test/thread/test_thread.rb
index 44ae3b338d..fe5fdeffda 100644
--- a/test/thread/test_thread.rb
+++ b/test/thread/test_thread.rb
@@ -77,5 +77,43 @@ class TC_Thread < Test::Unit::TestCase
assert_equal("exit.", result[/.*\Z/], '[ruby-dev:30653]')
}
end
+
+ # This test checks that a thread in Mutex#lock which is raised is
+ # completely removed from the wait_list of the mutex
+ def test_mutex_exception_handling
+ m = Mutex.new
+ m.lock
+
+ sleeping = false
+ t = Thread.new do
+ begin
+ m.lock
+ rescue
+ end
+
+ sleeping = true
+ # Keep that thread alive: if the thread returns, the test method
+ # won't be able to check that +m+ has not been taken (dead mutex
+ # owners are ignored)
+ sleep
+ end
+
+ # Wait for t to wait for the mutex and raise it
+ while true
+ sleep 0.1
+ break if t.stop?
+ end
+ t.raise ArgumentError
+ assert(t.alive? || sleeping)
+
+ # Wait for +t+ to reach the sleep
+ while true
+ sleep 0.1
+ break if t.stop?
+ end
+
+ # Now unlock. The mutex should be free, so Mutex#unlock should return nil
+ assert(! m.unlock)
+ end
end
diff --git a/version.h b/version.h
index de11525de1..a04d9b76f9 100644
--- a/version.h
+++ b/version.h
@@ -2,7 +2,7 @@
#define RUBY_RELEASE_DATE "2007-09-17"
#define RUBY_VERSION_CODE 186
#define RUBY_RELEASE_CODE 20070917
-#define RUBY_PATCHLEVEL 105
+#define RUBY_PATCHLEVEL 106
#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 8