From 8079f8a6f25bd1e6ef9fa0bff569a850c31c6fb3 Mon Sep 17 00:00:00 2001 From: kosaki Date: Tue, 27 Nov 2012 02:00:09 +0000 Subject: * thread.c (thread_join): raises ThreadError if target thread is a current thread. * test/ruby/test_thread.rb (test_thread_join_current): test for the above. * NEWS: news for the above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37883 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 ++++++++ NEWS | 1 + test/ruby/test_thread.rb | 7 +++++-- thread.c | 4 ++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index d195780245..fea153073e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Tue Nov 27 09:24:47 2012 KOSAKI Motohiro + + * thread.c (thread_join): raises ThreadError if target thread + is a current thread. + * test/ruby/test_thread.rb (test_thread_join_current): + test for the above. + * NEWS: news for the above. + Tue Nov 27 10:37:44 2012 Aaron Patterson * ext/fiddle/handle.c: Make Fiddle independent of DL, copy DL::Handle diff --git a/NEWS b/NEWS index ad4392aa8c..7417fb0824 100644 --- a/NEWS +++ b/NEWS @@ -160,6 +160,7 @@ with all sufficient information, see the ChangeLog file. * incompatible changes: * Thread#join no longer allows to be used from trap handler. Now it raises ThreadError. + * Thread#join raises ThreadError if target therad is a current thread. * Time * change return value: diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb index 518ad40333..95f2c89db4 100644 --- a/test/ruby/test_thread.rb +++ b/test/ruby/test_thread.rb @@ -876,6 +876,9 @@ class TestThreadGroup < Test::Unit::TestCase } end - - + def test_thread_join_current + assert_raises(ThreadError) do + Thread.current.join + end + end end diff --git a/thread.c b/thread.c index e74cf6d14a..cdba4a2106 100644 --- a/thread.c +++ b/thread.c @@ -736,6 +736,10 @@ thread_join(rb_thread_t *target_th, double delay) rb_thread_t *th = GET_THREAD(); struct join_arg arg; + if (th == target_th) { + rb_raise(rb_eThreadError, "Target thread must not be current thread"); + } + arg.target = target_th; arg.waiting = th; arg.limit = timeofday() + delay; -- cgit v1.2.3