Fwd: kosaki:r37867 (trunk): * thread.c (rb_mutex_trylock, rb_mutex_unlock, mutex_sleep):

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 removed[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 @@
    • Thread#join

      See above.

    • Mutex#lock, Mutex#unlock, Mutex#try_lock, Mutex#synchronize and
      Mutex#sleep
  • See above.

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-dev:46434] [email protected]$7$?$H$-$K!“EvJ,(B
trap$B$+$i(Bmutex$B$,;H$([email protected])8B$OD>$5$J$$$H$$$&[email protected]$C$?$N$G!”%a!<%8E*$KNc30Ej$2$k$h$&$K$7$^$7$?(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

$B4X78$"$k$+$I$&$+$o$+$j$^$;$s$,!"[email protected]$5$s$,(Birc$B$G(Btry_lock$B$GMn$A$?$HH/[email protected]$7$?%m%0$,;D$C$F$$$?$N$G(B
[email protected]$1Nc30=P$5$J$$$h$&$KJQ$($^$7$?!#(B
try_lock$B$O(Bdeadlock$B$7$J$$$N$G!#(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#2$D$NM}M3$+$i9%$-$G$O$"$j$^$;$s!#(B1) mutex$B$,(Block
owner$B$rJ];}$7$F$$$k$N$,[email protected]$NA0Ds$K$J$C$F$$$k$,!"(Bdeadlock
detection$B$,$J$$<BAu$G$O$J$$$G$O$?$V$sJ];}$7$F$$$J$$$G$"$m$&(B
$B#2!K$=$l$G$O%@%a$J%W%m%0%i%`$r=q$$$?;~$K!"%F%9%H$GDL$C$FK\HV$GMn$A$k$H$$$&:G0-$N7k2L$K$J$C$F$7$^$$!"(Bdeadlock$B$+$i$?$$$7$F9%E>$7$F$$$J$$(B

$B;d$N9M$([email protected]$HNc30$O%W%m%0%i%`$,4V0c$C$F$$$k$H65$($F>e$2$k$?$a$K$"$2$F$$$k$N$G!"%F%9%H$7$?;~$K$&$C$+$jDL$C$F$7$^$&$h$&$J>r7o$O$"$^$j9%$-$G$O$J$/!“0lHLE*$K$O%l!<%9$7$F$=$&$J$iNc30$H$$$&>r7o$b$”$^$j9%$-$G$O$"$j$^$;$s!#(B

$B$I$&$;!"([email protected])8B$,$O$:$l$?$iNc30>e$,$i$J$/[email protected]$C$?$N$G!"$3$NJQ99A4BN$r(Brevert$B$9$k$N$b$"$j$G$9$,!"$=$b$=$b(Bdeadlock$B$7$F$&$l$7$$?M$O$$$k$s$G$9$+$M(B

$B$A$J$_$K!$(BPOSIX thread $B$O$I$&$J$C$F$k$s$G$7$?$C$1!%(B

trylock$B$b4^$a!"$9$Y$F(Bsignal$B%O%s%I%i$G;H$&$HF0:n$9$kJ]>Z$O$"$j$^$;$s(B

$B$I$b$I$b!%(B

(2012/11/28 11:29), KOSAKI Motohiro wrote:

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-dev:46434] [email protected]$7$?$H$-$K!"EvJ,(B

trap$B$+$i(Bmutex$B$,;H$([email protected])8B$OD>$5$J$$$H$$$&[email protected]$C$?$N$G!"%a!<%8E*$KNc30Ej$2$k$h$&$K$7$^$7$?(B

$B!!!V(B2.0 $B$G$O(B trap $B$G(B main $B$,%m%C%/$7$F$$$k$H$-$K$b$&0lEY(B
lock $B$r<h$m$&$H(B
$B$9$k$H%G%C%I%m%C%/$9$k$N$OD>$5$J$$!W$G$9$h$M!%(B

$B!!$J$N$G!$:#2s$NDs0F$O!V(Bmain
$B$,%m%C%/$7$F$$$k$H$-!W$H$$$&>r7o$rIU$1$h$&(B
$B$H$$$&OC$H$J$C$F$$$^$9!%(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

$B4X78$"$k$+$I$&$+$o$+$j$^$;$s$,!"[email protected]$5$s$,(Birc$B$G(Btry_lock$B$GMn$A$?$HH/[email protected]$7$?%m%0$,;D$C$F$$$?$N$G(B
[email protected]$1Nc30=P$5$J$$$h$&$KJQ$($^$7$?!#(B

try_lock$B$O(Bdeadlock$B$7$J$$$N$G!#(B

$B!!$=$&$G$9$M!%(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#2$D$NM}M3$+$i9%$-$G$O$"$j$^$;$s!#(B1) mutex$B$,(Block
owner$B$rJ];}$7$F$$$k$N$,[email protected]$NA0Ds$K$J$C$F$$$k$,!"(Bdeadlock
detection$B$,$J$$<BAu$G$O$J$$$G$O$?$V$sJ];}$7$F$$$J$$$G$"$m$&(B

$B!!B>$N<BAu$O!$Nc$($P(B trap $BCf$G(B main
$B$H6%[email protected]$,$"$k$N$G!$9M$($J(B
$B$/$F$bNI$$$H;W$$$^$9!%(BCRuby 2.0.0 [email protected])8B$H$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&!<$s!%Bg$-$JJQ99$J(B
$B$N$G!$$^$:$O7Y9p$r=P$9$h$&$K$9$k!$$H$$$&J}?K$O!$$=$l$O$=$l$G$"$j$J5$$b$7(B
$B$^$9$,!%(B

$B!!$A$g$C$H$^$H$^$j$^$;$s$,!$$H$j$"$($:Aw$C$F$*$-$^$9!%(B

$B$A$J$_$K!$(BPOSIX thread $B$O$I$&$J$C$F$k$s$G$7$?$C$1!%(B

trylock$B$b4^$a!"$9$Y$F(Bsignal$B%O%s%I%i$G;H$&$HF0:n$9$kJ]>Z$O$"$j$^$;$s(B

$B!!$J$k$[$I!$$=$&$G$7$?!%(B

mutex$B$NLdBj$O(Bmain
thread$B$G(Btrap$B$,5/[email protected]$N$"$k=j$G;[email protected]$1$J$N$G!"(Btrap$BFb$G0lN’6X;$9$k$N$O!"[email protected]$H;W$$$^$9!#(B
$BNc$($P(Btrap$B$r6X;
$7$F$+$i(Bmutex$B<h$k$H$+?’!9J}K!$O$"$k$o$1$G!#(B

$B;H$$J}$r4V0c$($?$i(Bdeadlock$B$G;_$^$k$N$O(Bthread$B4V$N$d$j<h$j$G$bF1$8!#(B

2012$BG/(B11$B7n(B28$BF|(B 12:22 SASADA Koichi [email protected]:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs