Mutex#lock $B$H$+$r!$(Btrap handler
$BCf$G=PMh$J$$!$$C$F$N$O!$$9$_$^$;$s!$$I$N(B
$BJU$NOC$G$7$?$C$1!%(B
ruby-spec $B$,$3$l$GMn$A$F$$$k$N$G5$$,$D$-$^$7$?!%(B
$B$9$_$^$;$s!$$3$l$C$F$=$&$$$&$b$N$G$7$?$C$1!%(B
$B$A$g$C$H!$Bg$-$9$.$k$h$&$K;W$$$^$7$F!%(B
main thread $B$H(B trap handler
$BCf$G6%9g$,H/@8$9$k!J%G%C%I%m%C%/$K$J$k!K$N$O(B
$B$o$+$k$s$G$9$,!%(B
$B$A$g$C$H$7$?2sHr:v$G$9$,!$(B
(1) main thread $B$,%m%C%/$rJ];}$7$F$$$k(B
$B;~$N$_!$(BMutex#lock $B$,Nc30$rH/@8$5$;$k(B
$B$H$$$&$N$O$I$&$G$7$g$&$+!%$3$l$K$h$C$F!$(B
(a) trap $BFb$G407k$9$k(B lock $B$O$A$c$s$HF0$/(B
$B!J(Btrap $BFb$G(B unlock $B$7$J$$E[$O;`$M$P$$$$!K(B
(b) sub-thread $B$G(B lock $B$7$F$$$kE[$O!$(Btrap
$BFb$GBT$D$3$H$,$G$-$k(B
$B$H=PMh$k$H;W$$$^$9!%$$$+$,$G$7$g$&$+!%(B
$B$A$J$_$K!$(BPOSIX thread $B$O$I$&$J$C$F$k$s$G$7$?$C$1!%(B
-------- Original Message --------
Subject: [ruby-changes:25810] kosaki:r37867 (trunk): * thread.c
(rb_mutex_trylock, rb_mutex_unlock, mutex_sleep):
Date: Tue, 27 Nov 2012 00:17:13 +0900 (JST)
From: kosaki [email protected]
Reply-To: [email protected]
To: [email protected]
kosaki 2012-11-27 00:17:01 +0900 (Tue, 27 Nov 2012)
New Revision: 37867
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37867
Log:
* thread.c (rb_mutex_trylock, rb_mutex_unlock, mutex_sleep):
raises ThreadError if called from trap handler as Thread#join.
* NEWS: news fot the above.
Modified files:
trunk/ChangeLog
trunk/NEWS
trunk/thread.c
Index: ChangeLog
— ChangeLog (revision 37866)
+++ ChangeLog (revision 37867)
@@ -1,3 +1,9 @@
+Tue Nov 27 00:13:41 2012 KOSAKI Motohiro [email protected]
+
-
- thread.c (rb_mutex_trylock, rb_mutex_unlock, mutex_sleep):
- raises ThreadError if called from trap handler as Thread#join.
-
- NEWS: news fot the above.
Mon Nov 26 23:55:33 2012 KOSAKI Motohiro [email protected]
- NEWS: update for Thread#join incompatible change.
Index: thread.c
===================================================================
— thread.c (revision 37866)
+++ thread.c (revision 37867)
@@ -4051,6 +4051,11 @@
VALUE locked = Qfalse;
GetMutexPtr(self, mutex);
-
/* When running trap handler */
-
if (GET_THREAD()->interrupt_mask & TRAP_INTERRUPT_MASK) {
-
rb_raise(rb_eThreadError, “can’t be called from trap context”);
-
}
-
native_mutex_lock(&mutex->lock);
if (mutex->th == 0) {
mutex->th = GET_THREAD();
@@ -4239,6 +4244,11 @@
rb_mutex_t *mutex;
GetMutexPtr(self, mutex); -
/* When running trap handler */
-
if (GET_THREAD()->interrupt_mask & TRAP_INTERRUPT_MASK) {
-
rb_raise(rb_eThreadError, “can’t be called from trap context”);
-
}
-
err = rb_mutex_unlock_th(mutex, GET_THREAD());
if (err) rb_raise(rb_eThreadError, “%s”, err);
@@ -4307,6 +4317,11 @@
{
VALUE timeout;
-
/* When running trap handler */
-
if (GET_THREAD()->interrupt_mask & TRAP_INTERRUPT_MASK) {
-
rb_raise(rb_eThreadError, “can’t be called from trap context”);
-
}
-
rb_scan_args(argc, argv, “01”, &timeout);
return rb_mutex_sleep(self, timeout);
}
Index: NEWS
===================================================================
— NEWS (revision 37866)
+++ NEWS (revision 37867)
@@ -105,6 +105,12 @@
* Module#const_get accepts a qualified constant string, e.g.
Object.const_get(“Foo::Bar::Baz”) -
- Mutex
-
- incompatible changes:
-
* Mutex#lock, Mutex#unlock, Mutex#try_lock, Mutex#synchronize
-
and Mutex#sleep no longer allows to be used from trap handler.
-
Now it raises ThreadError.
-
-
NilClass
- added method:
- added nil.to_h which returns {}
@@ -350,3 +356,7 @@
- added nil.to_h which returns {}
- added method:
-
Thread#join
See above.
-
-
- Mutex#lock, Mutex#unlock, Mutex#try_lock, Mutex#synchronize and
Mutex#sleep
- Mutex#lock, Mutex#unlock, Mutex#try_lock, Mutex#synchronize and
-
See above.