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IO$B$O;H$($k$Y$-!#(B
$B#3!%(Bmutex$B$b(BIO$B$b%H%i%C%W%O%s%I%i$+$i;H$($k$Y$-(B

$B#[email protected]$H!"$o$?$7$,(B[Bug #7134]
$B$K$O$C$?$h$&$J(BIO$BCf$O%H%i%C%W%O%s%I%i$N(Binvocation$B$r6X;_$9$k%^%9%/=hM}$r$$$l$k%Q%C%A$K$J$j$^$9$7!"#3$J$i!"[email protected]$5$s$,OC$7$F$$$?$h$&$K!K%H%i%C%W%O%s%I%i$r%a%$%s%9%l%C%I$GAv$i$;[email protected]%9%l%C%I$GAv$i$;$k$H$$$&2r$K$J$j$^$9!#(B

$B$H$3$m$G!"([email protected]$G%7%0%J%[email protected]%9%l%C%I$GAv$i$;$k$3$H$,$G$-$J$$$N$OC<E*[email protected]$($P(Blongjmp$B$GLa$C$F$3$l$k$3$H$r4|BT$7$F$kGZ$,[email protected]$,H/@8$9$k$+$i$G$9$,!"(BRuby$B$K$b;w$?$h$&$JLdBj$,$"$j$^$9!#(B

$B$r$_$k$H%H%i%C%W%O%s%I%i$+$i(Bcatch/throw$B$GH4$1$k$3$H$r$*$9$9$a$7$F$$$k?M$,$$$^$9!J$b$A$m$s$3$l$O4V0c$C$F$^$9!#(Bcatch$B$9$kA0$K(Bthrow$B$G$-$A$c$&$+$i!K(B

$B$3$l$r$^$8$a$K9M$($k$H(B
$B!&$=$b$=$b%H%i%C%W$+$i([email protected])8f$rLa$9$N$O9gK!$+!)(B
$B!&(Bthrow$B$GEj$2$?%%V%8%’%/%H$r%H%i%C%W%O%s%I%i%9%l%C%I$+$i%a%$%s%9%l%C%I$K%-%e!<$GEO$7$FHsF14|E$K<B9T$9$k$3$H$O5v$5$l$k$+(B
$B!&(Bthrow$B$7$?=V4V$O(Bcatch$B%V%m%C%/$NCf$K$$$?$1$I!"%-%e!<%$%s%0$7$F$k4V$K(B
catch$B%V%m%C%/$+$i30$l$F$7$^$C$?$h$&$J%1!<%9$K$*$$$F%9%/%j%W%H$+$i$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W$+$i([email protected])8f$rLa$9$N$O9gK!$+!)(B
$B463PE*[email protected]$($J$/$F?=$7Lu$J$$$N$G$9$,!"$3$l$O$5$9$,$KL5$7$8$c$J$$$G$7$g$&$+!#(B

$B0J>e$G$9!#(B

2012/11/9 Tomoyuki C. [email protected]:

$B$GBT$C$FFI$`$H$$$&$N$r$d$C$?$3$H$,$"$j$^$9!#%m%C%/$b;H$($J$$$7(BIO$B$b$G$-$J$$$H$J$k$H!"JQ?t$KBeF~$7$F4F;k$9$k$[$&$O(B
polling

$B$G8!=P$9$k$7$+$J$/$J$j!"$=$N>l9g%7%0%J%k$NAS<:$,$"$j$($k$H;W$$$^$9!#(B

$B$3$N0U8+$O$J$C$H$/$G$-$^$9$7!"B>$K0U8+$b$G$F$J$$$h$&$J$N$G#2$G?J$a$^$9!#[email protected]@)8B$,4K$/$J$kJ}$KJQ99$9$k$N$O$$$D$G$b$G$-$k$N$G>x$7JV$7$O4?7^$7$^$9!#(B

$B!&$=$b$=$b%H%i%C%W$+$i([email protected])8f$rLa$9$N$O9gK!$+!)(B

$B463PE*[email protected]$($J$/$F?=$7Lu$J$$$N$G$9$,!"$3$l$O$5$9$,$KL5$7$8$c$J$$$G$7$g$&$+!#(B

[email protected]$l$+(B
stackoverflow$B$K=q$-9~$$G$-$k?M$O$"$l$K%l!<%9$,$"$k$h!“F0$+$J$$$h$H%3%a%s%H$7$F$”$2$F$/[email protected]$5$$!#(B
$B5^n1%"%+%&%s%H:n$C$?$b$N$N:n$j$?$F$N%"%+%&%s%H$G$O%3%a%s%H=q$-9~$
$G$-$J$$$_$?$$(B

$B$"$^$j$^$H$^$C$F$$$J$$$N$G$9$,!$;[email protected]$7$F$*$-$^$9!%(B

(2012/11/10 0:41), KOSAKI Motohiro wrote:

$B$r;H$C$F%H%i%C%W%O%s%I%i$G=q9~$_!"4F;k$9$k%9%l%C%I$G(B IO.select

$B$GBT$C$FFI$`$H$$$&$N$r$d$C$?$3$H$,$"$j$^$9!#%m%C%/$b;H$($J$$$7(BIO$B$b$G$-$J$$$H$J$k$H!"JQ?t$KBeF~$7$F4F;k$9$k$[$&$O(B
polling

$B$G8!=P$9$k$7$+$J$/$J$j!"$=$N>l9g%7%0%J%k$NAS<:$,$"$j$($k$H;W$$$^$9!#(B

$B$3$N0U8+$O$J$C$H$/$G$-$^$9$7!"B>$K0U8+$b$G$F$J$$$h$&$J$N$G#2$G?J$a$^$9!#[email protected]@)8B$,4K$/$J$kJ}$KJQ99$9$k$N$O$$$D$G$b$G$-$k$N$G>x$7JV$7$O4?7^$7$^$9!#(B

$B!!$($($H!$!V(BMutex $B$,;H$($J$$!W$H$$$&$N$O!V(Btrap handler $B$O(B
main thread $B$H(B
$BF1$8(B context $B$J$N$G!$(Bmain thread $B$,(B Mutex $B$r(B lock
$B$7$F$$$k>l9g!$(Btrap
handler $BFb$G(B Mutex
$B$rDO$b$&$H$9$k$HNc30$,=P$F$7$^$&$+$i;H$($J$$!W$H$$$&(B
$B0UL#$G$"$C$F$^$9$h$M!%(B

$B!!0JA0(B ruby-core $B$G!$(BQueue $B$K(B true
$B$rFM$C9~$$h$&$K=q$$$?$i(B Mutex $B$,(B main thread $B$H6%9g$7$F$7$^$C$F;H$($J$$!$$H$$$&OC$,$"$C$F!$$=$N$H$-$O(B trap $B$G$OJ#;($J$3$H$,=PMh$J$$$3$H$,B?$$$+$i(B flag $B$rFM$C9~$[email protected]$1$K$7$h(B
$B$&!$$H$$$&JV;v$r$7$^$7$?!%MW$9$k$K6a1J$5$s$,$5$l$?(B pipe trick
$B$_$?$$$J$3(B
$B$H$r(B Queue
$B$r;H$C$F$d$k!$$C$FOC$J$N$G$9$,!$$=$j$c<[email protected]$h$J$!!$$H$$(B
$B$&5$$,$7$F$$$^$7$?!%(B

require ‘thread’
q = Queue.new
trap(:SIGINT){
q << true
}

q.pop # block until sigint


$B$H;W$C$?$i!$>e5-%3!<%I$O%G%C%I%m%C%/8!=P$,F/$$$FF0$+$J$$$s$G$9$J$!!%(B

/home/ko1/build/ruby/trunk/lib/thread.rb:192:in sleep': No live threads left. Deadlock? from /home/ko1/build/ruby/trunk/lib/thread.rb:192:inblock in pop’
from internal:prelude:10:in synchronize' from /home/ko1/build/ruby/trunk/lib/thread.rb:184:inpop’
from …/trunk/test.rb:7:in `’

$B!!(Bsignal $BMQ(B thread $B$rMQ0U$7$F$*$/$H!$(Bdeadlock
$B8!=P$,KX$I$&$^$/9T$+$J$/$J(B
$B$k$h$&$J5$$,$9$k$N$G!$$d$C$Q$J$7$G$$$$$+$J$!!%$$$d!$(Btrap handler
$B$,Dj5A(B
$B$5$l$?=V4V$K(B signal $BMQ(B thread
$B$rMQ0U$7$F$d$k$N$O0-$/$J$$5$$b$9$k!%(B
$B$,!$(B2.0.0 $B8~$1$8$c$J$$$G$9$J!%(B

$B!!>.:j$5$s$,!V$3$NJ}[email protected]!W$H$$$&$N$O!$6qBNE*$K$O$I$&$$$&OC$G$7$g$&(B
$B$+!%(BIO $B$N%m%C%/;~$K(B semaphore $B$d(B monitor
$B$N$h$&$K$7$F!$!VF1$8%9%l%C%I$G(B
$B%m%C%/$7$F$bL5;k!W$K$9$k46$8$G$7$g$&$+!%(Bsemaphore
[email protected]$HC1$K%G%C%I%m%C%/$7(B
$B$F;`K4$J$N$G!$(Bmonitor $B$+$J!%$=$&$9$k$H!$(B

  1. [main thread] IO $B$r(B lock
  2. [main thread] signal $B$K$h$j(B trap $B$r5/F0(B
  3. [trap handler] monitor#lock
  4. [trap handler] IO $B$9$k(B
  5. [trap handler] monitor#unlock
  6. [main thread] IO $B$9$k(B
  7. [main thread] monitor#unlock

$B$3$s$J46$8$G!$(Block $B$G<i$j$?$+$C$?(B IO
$B$O%m%C%/=PMh$F$$$k$s$G$7$g$&$+!$$H(B
$B$$$&5?Ld$,$"$j$^$9!%(B

$B!!$d$O$j:,K\E*$J2r7h:v$O!$2<5-$N$h$&$J46$8$G$7$g$&$+!%(B

(1) trap $B%O%s%I%[email protected]_Dj$9$k$H!$(Bsignal $B$,G[Aw$5$l$k$N$r$^$DBT5!(B
thread $B$r(B
[email protected]@.$9$k(B (signal thread $B$H8F>N$9$k!K(B
(2) trap $B%O%s%I%i$,$9$Y$F:o=|$5$l$k$H!$$=$N(B thread $B$O:o=|$5$l$k(B
(3) trap $B%O%s%I%iFb$G$NA4$F$NNc30$O(B main thread $B$X(B Thread#raise
$B$5$l$k(B

$B$G$7$g$&$+!%(B

$B$F$-$H!<$KMQ8l$rDj5A$7$J$$$G%U%#!<%j%s%0$GFI$s$G$b$i$&$H!$$3$s$J46$8!%(B
$B%9%l%C%I%;!<%U$8$c$J$$$N$O$40&7I!%(B

def trap(sig, &block) # $BLLE]$J$N$G(B cmd $B$ON,(B
if block
@@trap_handlers[sig] = block
@@signal_thread = Thread.new{
until @@trap_handlers.empty?
sig = sigwait()
begin
@@trap_handlers[sig].call(sig)
rescue CheckTrapHandler
# ignore
rescue Exception => e
main_thread.kill(e)
end
end
}
end unless @@signal_thread
else
@@trap_handlers.delete(sig)
@@signal_thread.raise(CheckTrapHandler) if @@signal_thread
end
end

$B!!H>G/$/$i$$Aa$/[email protected]$r$7$F$$$l$P!$$3$s$J$U$&$KJQ$($k$H$9$C$-$j$7(B
$B$?$s$8$c$J$$$+$H;W$$$^$9!%(B2.0.0 $B$G$O$I$&$7$^$9$+$M$’!%(B

$B!&$=$b$=$b%H%i%C%W$+$i([email protected])8f$rLa$9$N$O9gK!$+!)(B

$B463PE*[email protected]$($J$/$F?=$7Lu$J$$$N$G$9$,!"$3$l$O$5$9$,$KL5$7$8$c$J$$$G$7$g$&$+!#(B

[email protected]$l$+(B
stackoverflow$B$K=q$-9~$_$G$-$k?M$O$"$l$K%l!<%9$,$"$k$h!“F0$+$J$$$h$H%3%a%s%H$7$F$”$2$F$/[email protected]$5$$!#(B

$B5^n1%"%+%&%s%H:n$C$?$b$N$N:n$j$?$F$N%"%+%&%s%H$G$O%3%a%s%H=q$-9~$$G$-$J$$$$?$$(B

$B!!8=:_!$$?$^$?$^=PMh$A$c$&$N$,$M$(!%(B

2012$BG/(B11$B7n(B9$BF|(B 10:08 Tomoyuki C.
[email protected]:

$B;R%W%m%;%9$N=*N;$r(B SIGCHLD
$B$G8!=P$9$k$?$a$K!"%H%i%C%W%O%s%I%iFb$G%m%C%/$,;H$($J$$$N$G(B pipe
$B$r;H$C$F%H%i%C%W%O%s%I%i$G=q9~$_!"4F;k$9$k%9%l%C%I$G(B IO.select

$B$GBT$C$FFI$`$H$$$&$N$r$d$C$?$3$H$,$"$j$^$9!#%m%C%/$b;H$($J$$$7(BIO$B$b$G$-$J$$$H$J$k$H!"JQ?t$KBeF~$7$F4F;k$9$k$[$&$O(B
polling

$B$G8!=P$9$k$7$+$J$/$J$j!"$=$N>l9g%7%0%J%k$NAS<:$,$"$j$($k$H;W$$$^$9!#(B

$B$3$N(B the pipe trick $B$N$?$a$K%H%i%C%W%O%s%I%i$G(B IO
$B$r5v$9$H$$$&$N$O!"(B
IO
$B$r$9$Y$F;H$($k$h$&$K$7$J$1$l$P$J$i$J$$$H$$$&OC$G$O$J$$$h$&$K;W$$$^$9!#(B

pipe $B$NBg$-$5$OM-8B$G$"$j!"$$$C$Q$$$K$J$k$H=q$1$J$$(B
($B$G$b=q$1$J$$$H$-$O$J$s$i$+$N%G!<%?$,(B pipe $B$KF~$C$F$$$k$?$a!"(B
select $B$O(B readable $B$K$J$k$N$G=q$1$J$/$F$bLdBj$J$$(B) $B$N$G!"(B
write_nonblock [email protected]$1$G$$$$$s$8$c$J$$$G$7$g$&$+!#(B

$B6a1J$H?=$7$^$9!#(B

$B$($($H!$!V(BMutex $B$,;H$($J$$!W$H$$$&$N$O!V(Btrap handler $B$O(B
main thread $B$H(B

$BF1$8(B context $B$J$N$G!$(Bmain thread $B$,(B Mutex $B$r(B lock
$B$7$F$$$k>l9g!$(Btrap
handler $BFb$G(B Mutex $B$rDO$b$&$H$9$k$HNc30$,=P$F$7$^$&$+$i;H$($J$$!W$H$$$&(B
$B0UL#$G$"$C$F$^$9$h$M!%(B

$B$O$$!#$=$&$$$&0UL#$G$7$?!#(B
$BJdB-$7$F$$/$H!“8=>u$G$O%7%0%J%k%O%s%I%i$O:[email protected]$k(B($B%7%0%J%k%O%s%I%i<B9TCf$K:FEY%7%0%J%k%O%s%I%i$,5/F0$5$l$k(B)$B$N$G!”%a%$%s%9%l%C%I$G$OF1$8(B
Mutex $B$H$+(B Queue $B$H$+(B Monitor
$B$K?($i$J$$$h$&$K$7$F$b40A4$K$O2sHr$5$l$^$;$s!#(B
$B$J$N$G%7%0%J%k%O%s%I%iMQ$N%9%l%C%I$rF3F~$9$k$N$K2C$($F!"%7%0%J%k%O%s%I%i$N<B9TCf$K$OF1$8%7%0%J%k%O%s%I%i$N8F$S=P$7$O%^%9%/$5$l$k$H$$$&$N$bI,MW$+$J$!$H;W$C$F$
$j$^$9!#(B

$B$3$N0U8+$O$J$C$H$/$G$-$^$9$7!"B>$K0U8+$b$G$F$J$$$h$&$J$N$G#2$G?J$a$^$9!#[email protected]@)8B$,4K$/$J$kJ}$KJQ99$9$k$N$O$$$D$G$b$G$-$k$N$G>x$7JV$7$O4?7^$7$^$9!#(B

$B!!$($($H!$!V(BMutex $B$,;H$($J$$!W$H$$$&$N$O!V(Btrap handler $B$O(B main
thread $B$H(B
$BF1$8(B context $B$J$N$G!$(Bmain thread $B$,(B Mutex $B$r(B lock
$B$7$F$$$k>l9g!$(Btrap
handler $BFb$G(B Mutex $B$rDO$b$&$H$9$k$HNc30$,=P$F$7$^$&$+$i;H$($J$$!W$H$$$&(B
$B0UL#$G$"$C$F$^$9$h$M!%(B

$B$"$C$F$^$9!#(B

q << true
    from /home/ko1/build/ruby/trunk/lib/thread.rb:184:in `pop'
    from ../trunk/test.rb:7:in `<main>'

$B$=$&$G$9!#$$$^%Q%C%A$,$"$kJ}?K#[email protected]$H$3$l$O5_$($^$;$s!#(B

$B!!(Bsignal $BMQ(B thread $B$rMQ0U$7$F$*$/$H!$(Bdeadlock
$B8!=P$,KX$I$&$^$/9T$+$J$/$J(B
$B$k$h$&$J5$$,$9$k$N$G!$$d$C$Q$J$7$G$$$$$+$J$!!%$$$d!$(Btrap handler $B$,Dj5A(B
$B$5$l$?=V4V$K(B signal $BMQ(B thread $B$rMQ0U$7$F$d$k$N$O0-$/$J$$5$$b$9$k!%(B
$B$,!$(B2.0.0 $B8~$1$8$c$J$$$G$9$J!%(B

trap
handler$B$r;H$&%1!<%9$O$b$H$b$H(Bdeadlock$B8!=P$O$A$c$s$HF0$$$F$$$J$$$N$G$3$l0J>e0-2=$9$k$+$J$"$H$$$&$N$,[email protected]$C$?$j!#(B
$B$"$H!"$o$?$7$O(Bsignal$BMQ(Bthread$B$O(Btrap
handler$B=hM}@lMQ%9%l%C%IE*$J$b$N$r%$%a!<%8$7$F$$$?$N$G!"%9%l%C%I:[email protected]%?%$%_%s%0$G5sF0$,JQ$o$k$H$O;W$C$F$$$J$+$C$?(B

  1. [main thread] IO $B$9$k(B
  2. [main thread] monitor#unlock

$B$3$s$J46$8$G!$(Block $B$G<i$j$?$+$C$?(B IO
$B$O%m%C%/=PMh$F$$$k$s$G$7$g$&$+!$$H(B
$B$$$&5?Ld$,$"$j$^$9!%(B

$B$$$$$(!"$=$l$O(B[Bug #7134]
$B$G%P%0Js9p<T$,<gD%$7$F$$$?J}[email protected]$H;W$&$N$G$9$,(B(recursive
mutex$B$r;H$&!K!"%a%b%jGK2u$,5/$-$k$N$G$d$j$?$/$J$$$HJV;v$r$7$F$$$^$9!#(B

$B8=:_$N<BAu$O(B thread->trap_enabled
$B$H$$$&%U%i%0$rDI2C$7!"(Bfptr->write_lock$B$r$H$k$H$-$K$3$l$r(B
disable$B$KJQ$($F$7$^$&!#(B
$B$=$7$F!"(BRUBY_VM_CHECK_INTS()$B$G(B
trap_enabled$B$,#0$N$"[email protected]$O!"$?$H$((B
thread->interrupt_flag $B$,Hs#0$G$b(Btrap handler$B$r8F$S=P$5$J$$(B
$B!J:#5$$E$$$?$1$I!"E:IU$7$?%Q%C%A$O(B thread->interrupt_flag$B$N(B
0x2$B0J30$bL5;k$7$F$k$N$G$h$/$J$$$G$9$M!#$J$*$5$J$$$H!K(B

$B$3$NJ}[email protected]$H(B

$B!&(Bfptr->[email protected]$1$,FCJL07$$!#$b$H$b$H(Bruby$B$K$O8+$($F$J$$$3$C$=$j%m%C%/[email protected]$+$i5sF0$rJQ$($F$bHs8_49$G$O$J$$(B
$B!&(Bstdout$B$X$N(BIO$B$O$9$Y$F5v$5$l$k(B
$B!&(Bpipe$B$X$N(Bwrite$B$O(Bwrite_nonblock$B$r;H$&$+!“FI$_=P$7B&$r%5%V%9%l%C%I$K$7$J$$$H(BIO$B$G%V%m%C%-%s%0$7$F;I$5$k$3$H$O$”$j$($k!J8=>u$I$$j!K(B
$B!&(Btrap handler $B$H(Bmain thread$B$NN>J}$G(B mutex
class$B$r;H$C$?>l9g$O!"(Bdeadlock$B8!=P$G;`$L$3$H$O$"$j$&$k!J8=>u$I$
$j!K(B

$B$H$$$&46$8(B
focus$B$,(B trap { puts “hoge” }
$B$r5_$&$3$H$K=8Cf$7$F$k%P%s%I%(%$%I%Q%C%A!#(B

$B!!$d$O$j:,K\E*$J2r7h:v$O!$2<5-$N$h$&$J46$8$G$7$g$&$+!%(B

(1) trap $B%O%s%I%[email protected]_Dj$9$k$H!$(Bsignal $B$,G[Aw$5$l$k$N$r$^$DBT5!(B thread
$B$r(B
[email protected]@.$9$k(B (signal thread $B$H8F>N$9$k!K(B
(2) trap $B%O%s%I%i$,$9$Y$F:o=|$5$l$k$H!$$=$N(B thread $B$O:o=|$5$l$k(B
(3) trap $B%O%s%I%iFb$G$NA4$F$NNc30$O(B main thread $B$X(B Thread#raise
$B$5$l$k(B

$B$G$7$g$&$+!%(B

$B$o$?$7$N%$%a!<%8$O$=$s$J46$8(B

        @@trap_handlers[sig].call(sig)
  @@signal_thread.raise(CheckTrapHandler) if @@signal_thread

[email protected]$l$+(B
stackoverflow$B$K=q$-9~$_$G$-$k?M$O$"$l$K%l!<%9$,$"$k$h!“F0$+$J$$$h$H%3%a%s%H$7$F$”$2$F$/[email protected]$5$$!#(B

$B5^n1%"%+%&%s%H:n$C$?$b$N$N:n$j$?$F$N%"%+%&%s%H$G$O%3%a%s%H=q$-9~$$G$-$J$$$$?$$(B

$B!!8=:_!$$?$^$?$^=PMh$A$c$&$N$,$M$(!%(B

$B8=>u$9$G$K2?2s$+$K0l2s$O$.$c$C$H$J$k$H$$$&%3!<%I$7$+=q$1$J$$>uBV$J$N$G!"(Bthrow$B$bHsF14|$K$J$2$k$h$&$K$7$F$b<+BN$O$"$s$^$j0-2=$7$J$$$N$G$O!#$H$$$&$"$^$j:,5r$N$J$$M=46$,$"$C$?$j!#[email protected]$C$F!"$$$^[email protected]$b$s!#(B

$B$^$?$O(Btrap
handler$B$+$i(Bthrow$B$7$?$H$-$K>o$K%(%i!<$K$J$k$h$&$K%(%i!<%A%’%C%/$r6/2=$9$k$H$$$&$N$b!"2?2s$+$K0l2s<:[email protected]$J$N$G!"5v$5$l$kJ}?K$H$$$&G’<1(B

      rescue Exception => e

$B!!(B
$BH>G/$/$i$$Aa$/[email protected]$r$7$F$$$l$P!$$3$s$J$U$&$KJQ$($k$H$9$C$-$j$7(B

$B$?$s$8$c$J$$$+$H;W$$$^$9!%(B2.0.0 $B$G$O$I$&$7$^$9$+$M$’!%(B

$B!!<BAu$b$3$s$J46$8$GF10U$G$7$g$&$+!%(B

$B!!$b$&!$$$$C$=$$$m$$$mLLE]$J$s$G!$JQ$($A$c$&!)!!1sF#$5$s$,(B ok $B$C$F$$$C$?(B
$B$iJQ$($F$b$h$5$=$&[email protected]$,!$$A$g$C$HBg$-$9$.$k$+$J$!!%(B

$B%H%i%C%W%O%s%I%i%9%l%C%I$b%?%$%^!<%9%l%C%I$HF1$8$/FCJL07$$$rMQ0U$7$F(Bfork
safe$B$K$9$k$H$$$&2~B$$,5v$5$l$k$J$i!"$3$N0F$G$bKM$O0[[email protected]$"$j$^$;$s(B

(2012/11/11 8:13), KOSAKI Motohiro wrote:

$B!!(Bsignal $BMQ(B thread $B$rMQ0U$7$F$*$/$H!$(Bdeadlock
$B8!=P$,KX$I$&$^$/9T$+$J$/$J(B

$B$k$h$&$J5$$,$9$k$N$G!$$d$C$Q$J$7$G$$$$$+$J$!!%$$$d!$(Btrap handler $B$,Dj5A(B
$B$5$l$?=V4V$K(B signal $BMQ(B thread $B$rMQ0U$7$F$d$k$N$O0-$/$J$$5$$b$9$k!%(B
$B$,!$(B2.0.0 $B8~$1$8$c$J$$$G$9$J!%(B

trap
handler$B$r;H$&%1!<%9$O$b$H$b$H(Bdeadlock$B8!=P$O$A$c$s$HF0$$$F$$$J$$$N$G$3$l0J>e0-2=$9$k$+$J$"$H$$$&$N$,[email protected]$C$?$j!#(B
$B$"$H!"$o$?$7$O(Bsignal$BMQ(Bthread$B$O(Btrap

handler$B=hM}@lMQ%9%l%C%IE*$J$b$N$r%$%a!<%8$7$F$$$?$N$G!"%9%l%C%I:[email protected]%?%$%_%s%0$G5sF0$,JQ$o$k$H$O;W$C$F$$$J$+$C$?(B

$B!!;d$b$=$&$$$&%$%a!<%8$G$9$,!$!V%9%l%C%I:[email protected]%?%$%_%s%0$G5sF0$,JQ$o$k$H$O(B
$B;W$C$F$$$J$+$C$?!W$H$$$&$N$O$I$&$$$&OC$G$7$g$&$+!%2<5-$N5<;w%3!<%I;2>H!%(B

$B!&(Btrap handler $B$H(Bmain thread$B$NN>J}$G(B mutex
class$B$r;H$C$?>l9g$O!"(Bdeadlock$B8!=P$G;`$L$3$H$O$"$j$&$k!J8=>u$I$*$j!K(B

$B$H$$$&46$8(B
focus$B$,(B trap { puts “hoge” } $B$r5_$&$3$H$K=8Cf$7$F$k%P%s%I%(%$%I%Q%C%A!#(B

$B!!$A$g$C$HBg$2$5$J5$$,$9$k$1$I!$$^$!$$$$$N$+$J$!!%(B

      begin
  @@trap_handlers.delete(sig)
  @@signal_thread.raise(CheckTrapHandler) if @@signal_thread
end

end

$B!!H>G/$/$i$$Aa$/[email protected]$r$7$F$$$l$P!$$3$s$J$U$&$KJQ$($k$H$9$C$-$j$7(B
$B$?$s$8$c$J$$$+$H;W$$$^$9!%(B2.0.0 $B$G$O$I$&$7$^$9$+$M$’!%(B

$B!!<BAu$b$3$s$J46$8$GF10U$G$7$g$&$+!%(B

$B!!$b$&!$$$$C$=$$$m$$$mLLE]$J$s$G!$JQ$($A$c$&!)!!1sF#$5$s$,(B ok
$B$C$F$$$C$?(B
$B$iJQ$($F$b$h$5$=$&[email protected]$,!$$A$g$C$HBg$-$9$.$k$+$J$!!%(B

$B!&$=$b$=$b%H%i%C%W$+$i([email protected])8f$rLa$9$N$O9gK!$+!)(B

$B463PE*[email protected]$($J$/$F?=$7Lu$J$$$N$G$9$,!"$3$l$O$5$9$,$KL5$7$8$c$J$$$G$7$g$&$+!#(B

[email protected]$l$+(B
stackoverflow$B$K=q$-9~$_$G$-$k?M$O$"$l$K%l!<%9$,$"$k$h!“F0$+$J$$$h$H%3%a%s%H$7$F$”$2$F$/[email protected]$5$$!#(B

$B5^n1%"%+%&%s%H:n$C$?$b$N$N:n$j$?$F$N%"%+%&%s%H$G$O%3%a%s%H=q$-9~$$G$-$J$$$$?$$(B

$B!!8=:_!$$?$^$?$^=PMh$A$c$&$N$,$M$(!%(B

$B8=>u$9$G$K2?2s$+$K0l2s$O$.$c$C$H$J$k$H$$$&%3!<%I$7$+=q$1$J$$>uBV$J$N$G!"(Bthrow$B$bHsF14|$K$J$2$k$h$&$K$7$F$b<+BN$O$"$s$^$j0-2=$7$J$$$N$G$O!#$H$$$&$"$^$j:,5r$N$J$$M=46$,$"$C$?$j!#[email protected]$C$F!"$$$^[email protected]$b$s!#(B

$B!!:#F0$$$F$$$J$$!$$H$$$&$N$O!V%?%$%%s%0$K$h$C$F$OF0$+$J$$>l9g$,$"$k!W$H(B
$B$$$&0UL#$G$$$$$G$7$g$&$+!%;d$N<gD%$O!$!V%?%$%
%s%0$K$h$C$F$OF0$/>l9g$,$"(B
$B$k!W!$$7$+$b!VF0$/%?%$%_%s%0$,KX$I$G$"$k!W$H$$$&8=>uG’<1$G$9!%(B

$B$^$?$O(Btrap
handler$B$+$i(Bthrow$B$7$?$H$-$K>o$K%(%i!<$K$J$k$h$&$K%(%i!<%A%’%C%/$r6/2=$9$k$H$$$&$N$b!"2?2s$+$K0l2s<:[email protected]$J$N$G!"5v$5$l$kJ}?K$H$$$&G’<1(B

$B!!$=$l$OF10U!%(B

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