ThreadGroup の強化案

$B1J0f!wCNG=!%6e9)Bg$G$9!%(B

$B$h$&$d$/>/$7;~4V$,$G$-$?$N$G!$(BThreadGroup
$B$N6/2=$r9M$($?$$$H;W$$$^$9!%(B
$B0F$r:n$C$F$_$^$7$?$N$G8f0U8+$r$$$?$@$1$k$H4r$7$$$G$9!%(B

$B%Q%C%A$OL$40$G$4$a$s$J$5$$!%(B

$B!V%Q%C%A$,$G$-$?$i9M$($k!W$H$$$&$@$1$N0U8+$G$b(B

coding $B:n6H$NM%@h=g0L$r>e$2$k%b%A%Y!<%7%g%s$K$J$j$^$9!%(B(^_^)

============================================================================

[ ThreadGroup $B$N6/2=%W%i%s(B ]

*** $B$O$8$a$K(B ***
Ruby $B$N(B ThreadGroup $B$O!$C1$J$k(B Thread
$B=89g$N@)8f$@$1$G$O$J$/!$(B
Thread $B@[email protected]$K(B ThreadGroup $B$rJQ99$G$-$k$H$$$&@-<A$K$h$j!$(B
$B<jB3$-$d(B Thread ($B@8@.$5$l$k(B sub-thread $B$r4^$(B) $B$KA:n2DG=$JJ8L.$rM?$($?$j!$(B
$B4J0W(B sandbox $B:n@.$r;Y1g$7$?$j$9$k$3$H$b2DG=$G$"$k!%(B
$B$7$+$7$J$,$i!$8=:_$N(B ThreadGroup $B$N%a%=%C%I72(B ($B$H5!G=(B)
$B$O!$(B
$B$=$&$7$?MxMQ$r%5%]!<%H$9$k$K$O==J,$H$O8@$($J$$!%(B

$BNc$($P!$(Bthread $B72$K=hM}$rJ,;6$5$;$F7k2L$rF@$k>l9g$r9M$($k!%(B
thread $B72$r(B ThreadGroup $B$K$^$H$a$?$H$7$F$b!$(B
$B8=:$O(B ThreadGroup $BA4BN$KBP$9$k%a%=%C%I$K7g$1$k$?$a!$(B
$B7k6I$O(B thread $B72$N%j%9%H$rF@$F8DJL$K%a%=%C%I$r8F$VI,MW$,$"$k!%(B
$B$3$l$G$O$;$C$+$/(B ThreadGroup $B$r;HMQ$7$F$$$F$b!$$=$N2ACM$,Dc$$!%(B
$B$^$?!$%M%C%H%o!<%/$r2p$7$F$$$k$J$I$G(B thread
$B$,=hM}ESCf$GNc30=*N;$9$k2DG=@-$,$"$j!$(B
$B$=$N$h$&$J>l9g$O$9$0$KBeBX(B thread $B$r5/F0$9$kI,MW$,$"$k$H$9$k$H!$(B
$B%7%9%F%`$,BZ$j$J$/F0:n$9$k$K$OB??t$N(B thread
$B$Nu67$r4F;k$7B3$1$kI,MW$,$"$k!%(B
$B8=:
$N(B Ruby $B$G$3$l$r9T$&$K$O(B polling
$B$G>uBV$rDI$&I,MW$,$"$j!$8zN($,0-$$(B
($B$$$D$I$N(B thread $B$,$I$&$$$&M}M3$G=*N;$9$k$+$o$+$i$J$$$N$G(B join
$B$G$OBT$F$J$$$?$a(B)$B!%(B
ThreadGroup
$B$N6/2=%W%i%s$G$O!$$=$&$7$?%1!<%9$G$N=hM}8zN(2~A1$b4^$a$k!%(B

*** $BC1=c$J(B Thread $BA`:n%a%=%C%I$NITB-(B ***
$BFCDj$N(B ThreadGroup $B$K(B Thread $B$r@8@.$9$k$K$O!$(B
Thread $B$r@8@.$7$?>e$GBP>]$N(B ThreadGroup $B$K0\F0$9$k$7$+$J$+$C$?!%(B
$B$7$+$7$=$l$G$O(B ThreadGroup $B$r0\F0$9$kA0$K(B
Thread $B$N=hM}$,?J9T$7$F$7$^$&2DG=@-$,9b$/!$(B
$B$=$l$r2sHr$9$k$?$a$K(B Thread $B$r0lC6(B stop $B$7$F$*$$$F(B
$B0\F08e$K(B wakeup $B$9$kI,MW$,$"$C$?!%(B

$B$3$NLdBj$X$NBP:v$H$7$F!$(BThreadGroup#new_thread $B$rF3F~$9$k!%(B
$B<B9T$K$O!$8=:_$N(B ThreadGroup $B$G@8@.$7$?(B thread $B$r(B
$B%l%7!<%P$N(B ThreadGroup
$B$K0\F0$9$k8"8B$r;}$D$3$H$,I,MW$G$"$k$H$9$k!%(B

$B$=$NB>!$Nc$($P(B ThreadGroup $B$KB0$9$k(B Thread
$B$9$Y$F$N=*N;$rBT$D$h$&$J%a%=%C%I(B
ThreadGroup#join $B$N$h$&$K!$(BThreadGroup $B$r(B Thread
$B=89g$H$7$FA`:n$9$k$?$a$K(B
$BITB-$H;W$($k%a%=%C%I$rDI2C$9$k!%(B

*** ThreadGroup $B$N(B dominate ***
$B8=:_$N(B ThreadGroup $B$G$O!$(Benclose $B$5$l$?>l9g$K(B
$B30It$+$i(B Thread $B$rF3F~$9$k<jCJ$,$J$$!%(B
enclose $B$H$O$=$&$$$&$b$N$@$+$i$H$$$&OC$O$"$k$,!$(B
enclose $B$5$l$?(B ThreadGroup $B$r4F;k$9$k(B Thread (ThreadGroup)
$BB&$+$i$9$k$H!$(B
$B>/!9?45v$J$$@)Ls$G$"$k!%(B
$BNc$($P!$4F;kBP>]$N(B ThreadGroup $BFb$K4IM}MQ(B Thread
$B$NN`$,I,MW$H$J$j$&$k$J$i!$(B
enclose $B$9$kA0$K$=$&$7$?(B Thread $B$r@8@.$7$F$*$/I,MW$,$"$k!%(B
$B$^$?!$$b$72?$i$+$N%H%i%V%k$G4IM}MQ(B Thread
$B$,Mn$A$F$7$^$&$H2sI|$NJ}K!$,$J$$!%(B

$B$=$3$G!$(BThreadGroup $B4V$K(B dominate $B$H$$$&4X78$r5,Dj$9$k!%(B
$B$"$k(B ThreadGroup A $B$,JL$N(B ThreadGroup B $B$r(B dominate
$B$7$F$$$k$J$i$P!$(B
A $B$KB0$9$k(B Thread $B$O!$(BB $B$K!$$"$k$$$O(B B $B$+$i(B Thread
$B$r0\F0$5$;$k$3$H$,$G$-$k!%(B
$B$?$@$7!$(BB $B$@$1$G$J$/(B Thread $B$N0\F085(B/$B0\F0@h$K$b(B A
$B$,0\F08"8B$r;}$?$M$P$J$i$J$$!%(B
Thread $B$N0\F08"8B$r;}$D$N$O(B ThreadGroup $B$NA`:n8"8B$r;}$D>l9g$G!$(B

  • $BBP>]$,@)LsL5$7$N(B ThreadGroup
  • $BBP>]$,(B domanated $B$G!$<+?H$,BP>]$r(B dominate $B$7$F$$$k(B
    ThreadGroup $B$N(B Thread
    $B$N$$$:$l$+$N>l9g$G$"$k!%(B

dominate $B$7$F$$$k(B ThreadGroup A $B$H$N4X78$r=|$$$F$O!$(B
dominate $B$5$l$F$$$k(B ThreadGroup B $B$O(B enclose
$B$5$l$F$$$k>l9g$HF1$8@)Ls$r;}$D!%(B

$B$J$!$(Bdominated $B"(B enclosed $B"*(B frozen
$B$N4X78$O0lJ}DL9T$G$"$j!$(B
$B>uBVJQ998e$O85$KLa$9$3$H$O$G$-$J$$!%(B

*** Thread $B$,;}$D%"%/%;%98"8B(B ***
$B8=:_$N(B ThreadGroup $B$K$O!$(B
ThreadGroup $B4D6-$+$i$N(B Jail Break $B$rKI$0$?$a$N(B enclose
$B$H$$$&5!9=$,$"$k$,!$(B
enclose $B$5$l$?(B ThreadGroup $BFb$N(B Thread
$B$N8"8B$K$D$$$F$O$-$A$s$H$7$?5,Dj$,$J$$!%(B

ThreadGroup $B$r(B enclose $B$9$kL\E*$O!$(BThreadGroup
$B$K$h$C$FM?$($i$l$?J8L.$+$i(B
$BITMQ0U$KN%C&$7$F$7$^$o$J$$$h$&$K$H$$$&0BA4:v$N0UL#$b$"$k$,!$(B
$BFCDj$N(B Thread $B72$r?.MQ$G$-$J$$$H$$$&%1!<%9$b$"$k$@$m$&!%(B
$B$=$&9M$($k$H!$(Benclose $B$d(B freeze $B$5$l$?(B ThreadGroup $B$+$i(B
$BB>$N(B ThreadGroup $B$KB0$9$k(B Thread
$B$rA:n$9$k$3$H$OG'$a$k$Y$-$G$O$J$$$H8@$($k!%(B $B5U$K!$$=$&$7$?A:n$r5v$9$3$H$,$G$-$k$N$J$i!$(B
$B$o$6$o$6(B enclose $B$d(B freeze $B$r$9$kI,MW$OK3$7$$$H9M$($k!%(B

$B$h$C$F!$(Benclose $B$^$?$O(B freeze $B$5$l$?(B ThreadGroup $B$N(B
Thread $B$,!$(B
$B8"8B$N$J$$B>$N(B ThreadGroup $B$N(B Thread
$B$rA`:n$9$k$3$H$r6X;_$9$k$3$H$,K>$^$7$$!%(B
$B6qBNE*$K$O!$(BThread $B$N%$%s%9%?%s%9%a%=%C%I$NFb!$(B

[]=, abort_on_exception=, exit, kill, terminate,
priority=, raise, run, wakeup

$B$G$"$k(B ($B>uBV;2>H$O5v$9$,!$>uBVJQ99$O5v$5$J$$(B)$B!%(B
$B$7$+$7!$8_49@-$r<:$&$?$a$K$3$N@)Ls$rD>@\F3F~$9$k$3$H$OFq$7$$$@$m$&!%(B
$B$f$($K!$%G%U%)%k%H$G$O=>MhDL$j@)Ls$O$J$7$H$7$F$*$-!$(B
$B@)Ls$r@_Dj4IM}$9$k$?$a$N%a%=%C%I$H$7$F(B
ThreadGroup#lock, ThreadGroup#locked? $B$rF3F~$9$k!%(B
$B$3$N>l9g!$(Benclose $B$J$I$r$5$l$F$$$J$$(B ThreadGroup $B$K(B
$B@)Ls$rIUM?$9$k$3$H$b2DG=$G$O$"$k(B
($B%f!<%9%1!<%9$OK3$7$=$&$@$,!D(B)$B!%(B

*** ThreadGroup $B$N(B thread_queue ***
$BKAF,$G=R$Y$?$h$&$J(B polling $B$NLdBj$r2sHr$9$k$?$a$K!$(B
$B=*N;$7$?(B thread $B$r<u$1$H$k$?$a$N(B thread_queue $B$r(B ThreadGroup
$B$,;}$F$k$h$&$K$9$k!%(B
thread_queue $B$O!$=*N;$7$?(B Thread $B$r(B
$B=*N;=g$K$G$-$k$@$1Aa$/3Z$K=hM}$K$+$1$k$?$a$N5!9=$G$"$k!%(B

$B$b$A$m$s!$F0:n$5$;$k(B thread $B$N=hM}FbMF$K(B
$B=N;$r%l%]!<%H$9$k=hM}$r=q$$$F$$/$H$$$&J}K!$b$J$$$o$1$G$O$J$$$,!$(B
$B$=$l$r<BAu$9$k$H$J$k$H>/!9LLE]$G$"$m$&!%(B
$B=N;$7$?(B thread $B$,<+F0E$KFCDj$N(B queue $B$KDI2C$5$l$k$J$i(B
($B$3$N=hM}$O(B C $B%l%Y%k$G(B Coding $B$9$kI,MW$,$"$k(B)$B!$(B
$B4IM}B&$,$=$N(B queue $B$+$iFI$_=P$7$F<B9T$9$k=hM}$r=q$/$@$1$GNI$/!$(B
$BLLE]$JItJ,$r1#JC$9$k$3$H$,$G$-$k!%(B
$B4IM}BP>]$H$J$k$N$O(B Thread $B$N=89g$G$"$k$+$i!$(B
ThreadGroup $B$K$=$&$7$?(B queue $B$r;}$?$;$k$N$OBEEv$H8@$($k!%(B

thread_queue $B$O0l$D$N(B ThreadGroup $B$K$D$-0l$D$@$1$H$9$k!%(B
thread_queue $B$N%b!<%I$O!$(B(1) $B;HMQ$7$J$$!$(B(2) $BNc30$r@8$8$?(B
Thread $B$N$_$rDI2C$9$k!$(B
(3) $B$9$Y$F$N(B Thread $B$rDI2C$9$k!$$N#3<oN`$G$"$k(B
($B%G%U%)%k%H$O!V(Bthread_queue $B$r;HMQ$7$J$$!W(B)$B!%(B

$B%a%b%j>CHq$NGzH/$rHr$1$k$?$a!$%G%U%)%k%H$G$O(B thread_queue
$B$N%5%$%:$rM-8B$H$7!$(B
$BJ];}%5%$%:$rD6$($?>l9g$O8E$$(B Thread $B$+$i<N$F$k$3$H$H$9$k!%(B

thread_queue $B$N%"%/%;%9$K$O8"8B$,I,MW$G$"$k!%(B
$B<+$i$,@)Ls$r;}$?$J$$$+!$<+$i$,BP>]$N(B ThreadGroup $B$r(B dominate
$B$7$F$$$k>l9g$K8B$j!$(B
$BBP>]$N(B ThreadGroup $B$N(B thread_queue
$B$X$N%"%/%;%9$r5v$9$3$H$H$9$k!%(B

*** ThreadGroup $B$N8GM-%G!<%?(B ***
Thread $B$KJ8L.$rM?$($k$?$a$K$O(B ThreadGroup
$B$KJ8L.$r5,Dj$9$k%G!<%?$rJ];}$5$;$k!%(B
$B$b$7?7$7$$(B Thread $B$,@8@.$5$l$F$b!$<+F0E*$K8=:_$N(B ThreadGroup
$B$K=jB0$9$k$?$a!$(B
ThreadGroup $B$K$h$kJ8L.$,J];}$5$l$k(B (ThreadGroup
$B$r0\F0$9$l$P!$J8L.$bJQ99$5$l$k(B)$B!%(B

$B$3$l$^$G$O(B Thread $B$N$h$&$K(B ThreadGroup
$B$K8GM-%G!<%?$r;}$?$;$k$?$a$N%a%=%C%I$,(B
$BDj5A$5$l$F$O$$$J$+$C$?$?$a!$(BThread
$B%/%i%9F1MM$K8GM-%G!<%?$r07$&%a%=%C%I$rDI2C$9$k!%(B

*** $B%a%=%C%I0lMw(B ***
ThreadGroup.new()
ThreadGroup.new(hash)
ThreadGroup $B8GM-%G!<%?$r@_Dj$9$k0z?t$rDI2C(B
current ThreadGroup $B$r?F(B ThreadGroup $B$H$7$FJ];}$9$k(B

ThreadGroup.current
Thread.current.group $B$KF1$8(B

ThreadGroup#add(thread)
ThreadGroup#list
$B=>Mh$HF1$8(B

ThreadGroup#enclose
ThreadGroup#enclosed?
$B=>Mh$HF1$8(B
$B$?$@$7!$(Bdominated $B$G$"$l$P(B enclosed? $B$O(B true $B$H$J$k(B

ThreadGroup#lock
ThreadGroup#locked?
$BB>$N(B ThreadGroup $B$KB0$9$k(B Thread
$B$NA`:n@)Ls$N@_Dj$H>uBV;2>H(B

ThreadGroup#[]
ThreadGroup#[]=
ThreadGroup#key?(key)
ThreadGroup#keys
ThreadGroup $B8GM-%G!<%?$X$N%"%/%;%9(B
$B8=:_$N(B ThreadGroup
$B$,%l%7!<%P$NA:n8"8B$r;}$?$J$$>l9g$K$O;2>H!&JQ99$OIT5v2D(B ( $B8=:_$N(B ThreadGroup == $B%l%7!<%P$N>l9g$OA:n8"8B$"$j(B )

ThreadGroup#new_thread(){ … }
$B%l%7!<%P$N(B ThreadGroup $B$K?7$7$$(B thread $B$r@8@.(B
(Thread.new$B$HF1$8(B)
$B0z?t$O(B Thead#new $B$HF1$8(B
$B<B9T$O!$8=:_$N(B ThreadGroup $B$+$i%l%7!<%P$X$N(B Thread
$B0\F08"8B$r;}$D$3$H$,I,MW(B

ThreadGroup#start_thread(){ … }
ThreadGroup#fork_thread(){ … }
$B%l%7!<%P$N(B ThreadGroup $B$K?7$7$$(B thread $B$r@8@.(B
(Thread.{start,fork}$B$HF1$8(B)
$B0z?t$O(B Thead#new $B$HF1$8(B
ThreadGroup#new_thread $B$H0c$C$F(B Thread#initialize $B$r8F$P$J$$(B
$B<B9T$O!$8=:_$N(B ThreadGroup $B$+$i%l%7!<%P$X$N(B Thread
$B0\F08"8B$r;}$D$3$H$,I,MW(B

ThreadGroup#dominated_by(threadgroup)
$B%l%7!<%P$r0z?t$N(B threadgroup $B$K$h$C$F(B dominate $B$9$k(B
$B%l%7!<%P$,(B enclose $B$5$l$F$$$J$1$l$P(B enclose $B$5$l$k(B
$B8=:_$N(B ThreadGroup
$B$,%l%7!<%P$H0z?t$H$NN>J}$KA`:n8"8B$r;}$?$J$1$l$PNc30$rH/@8(B
$B$b$7!$0z?t$N(B threadgroup == $B%l%7!<%P$J$i!$Nc30$rH/@8$9$k(B

ThreadGroup#dominate?(threadgroup)
$B%l%7!<%P$,(B threadgroup $B$r(B dominate $B$7$F$$$k$J$i(B true
$B$rJV$9(B
$B8=:$N(B ThreadGroup
$B$,%l%7!<%P$H0z?t$H$NA`:n8"8B$r;}$?$J$$>l9g$K$ONc30$H$J$k(B
$B8=:
$N(B ThreadGroup == $B0z?t$N>l9g!$(Benclosed
$B0J>e$G$"$l$P8"8B$J$7$H$9$k(B
( enclosed $B0J>e$N(B ThreadGroup $B$,<+J,$N(B dominate
$B>uBV$rD4$Y$k$N$r6X;_$9$k$?$a(B )

ThreadGroup#dominated?
$B%l%7!<%P$r(B dominate $B$7$F$$$k(B ThreadGroup $B$rJV$9(B
$B8=:$N(B ThreadGroup
$B$,%l%7!<%P$NA`:n8"8B$r;}$?$J$$>l9g$K$ONc30$H$J$k(B
$B8=:
$N(B ThreadGroup == $B%l%7!<%P$N>l9g!$(Benclosed
$B0J>e$G$"$l$P8"8B$J$7$H$9$k(B
( enclosed $B0J>e$N(B ThreadGroup $B$,<+J,$N(B dominate
$B>uBV$rD4$Y$k$N$r6X;_$9$k$?$a(B )

ThreadGroup#join(exception=false)
ThreadGroup#join(limit, exception=false))
ThreadGroup $B$N$9$Y$F$N(B thread $B$,=*N;$9$k$N$rBT$D(B
$B0z?t(B limit ($BICC10L$N?tCM(B) $B$,;XDj$5$l$F$$$l$P!$$=$N;~4V$G(B
timeout $B$9$k(B
join $B$r8F$s$@8e$K@8@.$5$l$?(B thread $B$G$"$C$F$b=*N;$rBT$D(B
$B=*N;$7$?(B thread $B$rG[Ns$K$7$FJV$9(B
$B0z?t(B exception $B$K$D$$$F$O!$(B
nil $B$G$"$k$H$-$O!$Nc30$r@8$8$?(B thread $B$OGK4~$7$F$=$l0J30$N(B
hread $B$N$_$rJV$9(B
true $B$G$"$k$H$-$O!$Nc30$NM-L5$K8B$i$:$9$Y$F$N(B thread
$B$rLa$jCM$NG[Ns$K4^$a$k!%(B
false $B$N$H$-$O!$Nc30$r@8$8$?(B thread
$B$K=P2q$C$?;~E@$G$=$NNc30$rH/@8$5$;$k(B

ThreadGroup#values(exceptions=false)
$B$9$Y$F$N(B thread $B$NLa$jCM$rG[Ns$K$7$FJV$9(B
$BCM$H(B thread $B$H$NBP1~$,<h$l$J$$$N$G!$CM$@$1$,I,MW$J>l9g$KMQ$$$k(B
thread $B$H$NBP1~$,I,MW$J$i!$(Bjoin $B$GF@$?(B thread
$B$NG[Ns$KBP$7$F(B each $B$9$k$3$H(B
$B0z?t$,(B nil $B$G$"$k$H$-$O!$Nc30$r@8$8$?(B thread
$B$OGK4~$7$F$=$l0J30$NLa$jCM$N$_$rJV$9(B
$B0z?t$,(B true
$B$G$"$k$H$-$O!$Nc30$ONc30%*%V%8%’%/%H$H$7$FLa$jCM$NG[Ns$K4^$a$k!%(B
$B0z?t$,(B false $B$N$H$-$O!$Nc30$r@8$8$?(B thread
$B$K=P2q$C$?;~E@$G$=$NNc30$rH/@8$5$;$k(B

ThreadGroup#exit
ThreadGroup#kill
ThreadGroup#terminate
ThreadGroup $B$N$9$Y$F$N(B thread $B$r(B terminate $B$9$k(B
kill $B$r8F$s$@8e$K@8@.$5$l$?(B thread $B$G$"$C$F$b(B terminate
$B$9$k(B
$B<BBN$O$3$s$J46$8(B

current = Thread.current
Thread.exclusive do
until((lst = self.list - current).empty?) do
lst.each {|th| th.kill}
end
end
current.kill if current.group == self

ThreadGroup#thread_queue_pop(non_block=false)
thread queue $B$+$i=*N;$7$?(B thread $B$r0l$D<h$j=P$9(B

ThreadGroup#thread_queue_mode
ThreadGroup#thread_queue_mode=(mode)
$B=*N;$7$?(B thread $B$rC_$($k(B thread queue $B$N%b!<%I$N3NG’$H@Dj(B
nil : $B=*N;$7$?(B thread $B$rC
$($J$$(B ($B=>Mh$HF1MM$N>uBV(B)
false or :exception : $BNc30$G=*N;$7$?(B thread $B$@$1$rC_$($k(B
true or :all : $B=*N;$7$?(B thread $B$r$9$Y$FC_$($k(B

ThreadGroup#thread_queue_length
ThreadGroup#thread_queue_length=(len)
ThreadGroup#thread_queue_limit
ThreadGroup#thread_queue_limit=(len)
thread queue $B$N:GBgD9$r;2>H!&@_Dj$9$k(B
thread $B?t$NGzH/$rKI$0$?$a$N$b$N(B
$B:GBgD9$rD6$($k>l9g$O8E$$(B thread $B$+$i<N$F$i$l$k(B
$B%G%U%)%k%H$ND9$5$O!$G[Ns$N%G%U%)%k%HD9$5$HF1$8(B 16 $B$H$7$F$*$/(B

ThreadGroup#abort_on_exception
ThreadGroup#abort_on_exception=(state)
TreadGroup $BFb$N(B thread
$B$G$NNc30H/@8;~$K%$%s%?%W%j%?<+BN$r=*N;$5$;$k$+H]$+(B

ThreadGroup#raise
$B8=:_(B ThreadGroup $B$K=jB0$9$k$9$Y$F$N(B thread
$B$KNc30$rH/@8$5$;$k(B
$B?7$?$K@8@.$5$l$?(B thread
$B$K$^$GNc30$rH/@8$5$;$kI,MW$O$J$5$=$&$J$N$G!"(B
$B<BBN$O(B Thread.exclusive{threadgroup.list.each{|th| th.raise(…)}}
$B$H$9$k(B

ThreadGroup#alive?
$B8=:(B ThreadGroup $B$K=jB0$9$k(B thread $B$,B8:$9$l$P(B true
$B<BBN$O(B threadgroup.list.empty? $B$H$9$k(B

ThreadGroup#wakeup
$B8=:_(B ThreadGroup $B$K=jB0$9$k(B thread $B$N$9$Y$F$r5/$3$9(B
$B<BBN$OC1=c$K(B Thread.exclusive{threadgroup.list.each{|th|
th.wakeup}} $B$H$9$k(B

*** ThreadGroup $B$K$ODj5A$7$J$$M=Dj$N%a%=%C%I(B ***
Thread $B$K$"$k%a%=%C%I$NFb!$0J2<$O(B ThreadGroup
$B$G$N5!G=Dj5A$,Fq$7$$$N$G(B
$BF3F~$7$J$$M=Dj$G$"$k!%(B

ThreadGroup#value
$BJ#?t$N(B Thread $B$,BP>]$H$J$k$N$G!$(BThreadGroup#values $B$GDj5A(B

ThreadGroup#run
$B8=:(B ThreadGroup $B$K=jB0$9$k(B thread $B$N$9$Y$F$r5/$3$9(B
wakeup $B$O0UL#$,$"$k$H;W$&$,!$(Brun $B$O5?Ld(B
($B$I$l$K@)8f$r0$9$Y$-$+$,5,DjITG=(B)
$B8=:
$N(B thread list $B$K=g<!(B run
$B$r$+$1$k$H$$$&7A$O$"$jF@$k$,!%!%!%(B

ThreadGroup#priority
ThreadGroup#priority=
$B8=:_(B ThreadGroup $B$K=jB0$9$k(B thread
$B$N$9$Y$F$KBP$7$F@_Dj$9$k!%(B
thread $B$4$H$K0[$J$k2DG=@-$,9b$$$N$G!$;2>H$OIT2D!%(B

$B$R$C$8$g$&$K:,K\E*$J<ALd$r$9$k$N$G$9$1$l$I$b!"(BThreadGroup$B$C$F2?$K;H$&$s(B
$B$G$9$+!#(B

$B2a5n$K<c43$ND4::$r9T$C$?7k2L!"(BThread$B$rB+$K$7$FA:n$7$?$$$H$$$&MQES$K$O(B real world examples$B$,>/$J$9$.$F!"$$$^$$$A$G$9!#85$N%a!<%k$K$O(Bsandbox$B$H=q(B $B$$$F$"$j$^$9$1$l$I$b!">/$J$/$H$b8=>u$G$O(Bsandboxing$B$O(B$SAFE$B$,C4$C$F$$$kJ,(B $BLn$G$9$h$M(B? $B;d$b(B$SAFE$B$N5!G=$,40z$G$"$k$H$O8}$,3d$1$F$b8@$($^$;$s$,!"$@(B
$B$+$i$H$$$C$F(B$SAFE$B$G$O<B8=$G$-$J$$$h$&$J(Bsandboxing$B5!9=$,I,MW$J$N$@$H$7$?(B
$B$i!"$^$:$=$l$O(B$SAFE$B$r3HD%$9$k$3$H$G<B8=$9$k$N$,6Z$H$$$&$b$N$G$O$J$$$G(B
$B$7$g$&$+(B?
$B$=$&$G$O$J$/(BThreadGroup$B$r;H$&$3$H$G2?$,$I$&JXMx$K$J$k$N$+!"$,(B
$B;DG0$J$,$i8+$($F$-$^$;$s!#(B

ThreadGroup$B$K$O5!G=$,>/$J$9$.$k$+$i$I$&$K$+$7$h$&$H$$$&<q;]$K$O6/$/6&46(B
$B$9$k$b$N$N!"$G!"7k6I$I$&;H$&$N(B?
$B$H$$$&ItJ,$,L@3N$G$J$$$N$G!“5!G=$@$1DI2C(B
$B$7$F$b$d$C$Q$jLr$KN)$?$J$$$^$^$J$N$+$J$”$H$$$&$U$&$K;W$$$^$9!#(B

$B1J0f!wCNG=!%6e9)Bg$G$9!%(B

From: Urabe S. [email protected]
Subject: [ruby-dev:43920] Re: ThreadGroup#make_local_space! (Re:
ThreadGroup $B$N6/2=0F(B)
Date: Sun, 26 Jun 2011 17:23:06 +0900
Message-ID: [email protected]

$B$R$C$8$g$&$K:,K\E*$J<ALd$r$9$k$N$G$9$1$l$I$b!"(BThreadGroup$B$C$F2?$K;H$&$s(B
$B$G$9$+!#(B

$B2a5n$K<c43$ND4::$r9T$C$?7k2L!“(BThread$B$rB+$K$7$FA`:n$7$?$$$H$$$&MQES$K$O(B
real world examples$B$,>/$J$9$.$F!”$$$^$$$A$G$9!#(B

$B4pK\E*$K$OB+$M$k$b$N$G$7$g$&$M!%(B
$B$3$l$^$G$O5!G=$,>/$J$9$.$F!$(Bsub thread
$B$,<+F0E*$K4^$^$l$k$3$H$r=|$-!$(B
thread $B$r(B array $B$KF~$l$F4IM}$9$k$N$H$?$$$7$FJQ$o$i$J$+$C$?!$(B
$B$=$l$f$(!$$o$6$o$6;H$&5$$K$b$J$i$J$+$C$?$H$$$&$h$&$K;W$$$^$9!%(B
ThreadGroup $B$N5!G=6/2=$K$h$j!$(BThreadGroup
$B$H$$$&$b$N$N3hMQ$NI}$r9-$2!$(B
$B$R$$$F$O(B thread
$B3hMQ%W%m%0%i%_%s%0$NI}$b9-$2$i$l$J$$$+$H$$$&$N$,<q;]$G$9!%(B
$B!V$=$&$O8+$($J$$!W$H$$$&$N$G$"$l$P!$$=$l$O;d$NNOITB-$H$$$&$3$H$G$9!%(B

$BNc$($P(B thread pool $B$H$7$F;H$&$K$7$F$b!$(B
$B=hM}$r(B queue $B$GEO$7$F(B pool $B$N$$$:$l$+$N(B thread
$B$r5/$3$9$H$$$&$N$G$O(B
ThreadGroup $B$N$“$j$,$?$_$J$I$O$”$j$^$;$s!%(B
$B4F;k$9$kG=NO$,<e$$$?$a!$(Bthread
$B$N>uBVJQ2=$K9b$$B(1~@-$r;}$?$5$;$k$?$a$K$O(B
polling $B$7$?$j!$BP>](B thread $B$4$H$K#18D$N@lMQ4F;k(B thread
$B$rMQ0U$7$?$j(B
$B$9$kI,MW$,$"$j$^$9!%(B

ThreadGroup $B%*%V%8%'%/%H$K;}$?$;$h$&$H$9$k(B thread_queue $B$O!$(B
thread $B72$N4F;kG=NO$N6/2=$r?^$k$H$$$&0UL#9g$$$,$“$j$^$9!%(B
thread pool $B%3%s%H%m!<%k$N<gF38”$r4F;kB&$K0$9$3$H$,2DG=$H$J$j$^$9!%(B
$BNc$($P(B thread
$B72$,=hM}G=NO:9$N$"$kJL%^%7%s$K=hM}0MMj$r$9$k>l9g$G$b(B
$B3F(B thread $B$,=hM}40N;$KMW$7$?;~4V$r4F;k$70W$/$J$j$^$9$+$i!$(B
$B%9%1%8%e!<%j%s%0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r1x@w$9$k$?$a(B
$B6X;$5$l$F$b;EJ}$,$J$$B8:$G$9$,!$;H$($?J}$,4r$7$$$N$O3N$+$G$9!%(B

$B@h$N%5%s%W%k%9%/%j%W%H$K$O4^$s$G$$$^$;$s$,!$(B

ThreadGroup#make_local_space! $B$O4X?tE*%a%=%C%I$K$D$$$F$b(B

$BM-8z6u4V$r8BDj$G$-$^$9$N$G!$NI$+$C$?$i$*;n$7$/$@$5$$!%(B

$B4{B8$N%/%i%9$KBP$9$k%a%=%C%IDI2C$b$7$P$7$P9T$o$l$^$9$,!$(B
$B$3$l$b%0%m!<%P%k$JJQ99$K$J$j$^$9$+$i6X;_$5$l$k$Y$-$b$N$H$J$j$^$9!%(B
safe level $B$NLdBj0J30$N%1!<%9$G$b!$Dj5A$,43>D$79g$&%i%$%V%i%jEy$r(B
$BF1;~$K;H$$$?$$$H$$$&>l9g$bF1MM$NLdBj$r4^$s$G$$$^$9!%(B

$B$3$l$i$NLdBj$N$9$Y$F$r(B safe level
$B$N3HD%$GBP=h$G$-$k$H$O;W$($^$;$s!%(B
$B2>$K(B safe level $B$+$i$N%"%W%m!<%A$G2r7h$r?^$k$H$7$F$b!$(B
ThreadGroup $B$,4IM}C10L$H$J$C$F(B make_local_space! $B$N$h$&$J$b$N$,(B
$BI,MW$K$J$k$@$m$&$HM=A[$7$^$9!%(B
$B$J$i$P!$(Bsafe level $B$HL54X78$KM-8z$K;H$$$&$k(B make_local_space!
$B$r<BAu$7!$(B
$B$=$l$HAH$_9g$o$;$F(B safe level
$B$N5!G=6/2=$r9M$($k$N$bIT<+A3$H$O;W$($^$;$s!%(B

(2011/06/28 15:15), Hidetoshi NAGAI wrote:

real world examples$B$,>/$J$9$.$F!"$$$^$$$A$G$9!#(B

$B4pK\E*$K$OB+$M$k$b$N$G$7$g$&$M!%(B
$B$3$l$^$G$O5!G=$,>/$J$9$.$F!$(Bsub thread $B$,<+F0E*$K4^$^$l$k$3$H$r=|$-!$(B
thread $B$r(B array $B$KF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(B
ThreadGroup#make_local_space! $B$G$9!%(B
$B$3$l$O%a%=%C%IEy$K(B ThreadGroup $B8GM-$N6u4V$r:n$j$^$9!%(B
local space $B$r;}$D(B ThreadGroup $BFb$GDj5A$5$l$?%a%=%C%I$O(B
$B$=$N(B ThreadGroup $BFb$G$N$_M-8z$H$J$j$^$9!%(B
$BB>$N(B ThreadGroup
$B$G$O85!9$N%a%=%C%I$,8+$($F$*$j!$1F6A$r<u$1$^$;$s!%(B

$B%a%=%C%I$N(B undef $B$X$NBP1~$bI,MW$G$9$,!$$=$3$OL$<BAu$G$9!%(B

$B%a%=%C%I0J30$N(B local space $B$O$^$@<BAu$G$-$F$$$^$;$s!%(B

ThreadGroup $B8GM-$N6u4V$G$9$+$i!$(Bsub thread
$B$r:n@.$5$l$F$bBg>fIW$G$9!%(B
ThreadGroup#enclose $B$HAH$9g$o$;$k$3$H$G!$(B
sandbox $B:n@.$J$I$K$bLrN)$D$N$G$O$J$$$+$H;W$$$^$9!%(B
$B?7$7$$(B ThreadGroup $B$r:n@.$7$?$H$-$K$O!$$=$l$r:n@.$7$?(B thread
$B$N(B
ThreadGroup $B$,;}$D(B local space $B$r6&M-$9$k$h$&$K$7$F$$$^$9!%(B
$B$=$N?7$7$$(B ThreadGroup $B$G(B make_local_space! $B$r8F$V$H(B
$B8=:
$N(B local space $B$N%3%T!<$r:n@.$7$FFHN)$9$k$H$$$&;EMM$G$9!%(B

$B$3$NItJ,$OL$%F%9%H$G$9!%(B

$B0J2<$,%5%s%W%k%9%/%j%W%H$G$9!%(B
$B$I$N(B ThreadGroup
$B$G$I$N%a%=%C%IDj5A$,8+$($F$$$k$+$KCmL$/$@$5$$!%(B
$B8f0U8+$J$I$$$?$@$1$^$9$H9,$$$G$9!%(B

—<thgrp_local_space-sample.rb>------------------------------------
thgrp = ThreadGroup.new
class A
def A.bar
p [Thread.current.group, :BAR]
end
def A.foo
p [Thread.current.group, :HOGE]
end
def foo
p [Thread.current.group, :hoge]
end
end

a = A.new

A.bar; A.foo; a.foo

=> [#ThreadGroup:0x0000000087a988, :BAR]

[#ThreadGroup:0x0000000087a988, :HOGE]

[#ThreadGroup:0x0000000087a988, :hoge]

thgrp.new_thread{ A.bar; A.foo; a.foo }.join

=> [#ThreadGroup:0x00000000b89778, :BAR]

[#ThreadGroup:0x00000000b89778, :HOGE]

[#ThreadGroup:0x00000000b89778, :hoge]

Make local space on thgrp, and define on the local space

thgrp.make_local_space!
thgrp.new_thread{
def A.foo
p [Thread.current.group, :FUGA]
end
class A
def foo
p [Thread.current.group, :fuga]
end
end
}

thgrp.new_thread{ A.bar; A.foo; a.foo }.join

=> [#ThreadGroup:0x00000000b89778, :BAR]

[#ThreadGroup:0x00000000b89778, :FUGA]

[#ThreadGroup:0x00000000b89778, :fuga]

A.bar; A.foo; a.foo

=> [#ThreadGroup:0x0000000087a988, :BAR]

[#ThreadGroup:0x0000000087a988, :HOGE]

[#ThreadGroup:0x0000000087a988, :hoge]

Thread.new{
A.bar; A.foo; a.foo

=> [#ThreadGroup:0x0000000087a988, :BAR]

[#ThreadGroup:0x0000000087a988, :HOGE]

[#ThreadGroup:0x0000000087a988, :hoge]

thgrp.add Thread.current
A.bar; A.foo; a.foo

=> [#ThreadGroup:0x00000000b89778, :BAR]

[#ThreadGroup:0x00000000b89778, :FUGA]

[#ThreadGroup:0x00000000b89778, :fuga]

ThreadGroup::Default.add Thread.current
A.bar; A.foo; a.foo

=> [#ThreadGroup:0x0000000087a988, :BAR]

[#ThreadGroup:0x0000000087a988, :HOGE]

[#ThreadGroup:0x0000000087a988, :hoge]

}.join

============================================================================

[ ThreadGroup $B$N6/2=%W%i%s(B ]

*** $B$O$8$a$K(B ***
Ruby $B$N(B ThreadGroup $B$O!$C1$J$k(B Thread
$B=89g$N@)8f$@$1$G$O$J$/!$(B
Thread $B@[email protected]$K(B ThreadGroup $B$rJQ99$G$-$k$H$$$&@-<A$K$h$j!$(B
$B<jB3$-$d(B Thread ($B@8@.$5$l$k(B sub-thread $B$r4^$(B) $B$KA:n2DG=$JJ8L.$rM?$($?$j!$(B
$B4J0W(B sandbox $B:n@.$r;Y1g$7$?$j$9$k$3$H$b2DG=$G$"$k!%(B
$B$7$+$7$J$,$i!$8=:_$N(B ThreadGroup $B$N%a%=%C%I72(B ($B$H5!G=(B)
$B$O!$(B
$B$=$&$7$?MxMQ$r%5%]!<%H$9$k$K$O==J,$H$O8@$($J$$!%(B

$BNc$($P!$(Bthread $B72$K=hM}$rJ,;6$5$;$F7k2L$rF@$k>l9g$r9M$($k!%(B
thread $B72$r(B ThreadGroup $B$K$^$H$a$?$H$7$F$b!$(B
$B8=:$O(B ThreadGroup $BA4BN$KBP$9$k%a%=%C%I$K7g$1$k$?$a!$(B
$B7k6I$O(B thread $B72$N%j%9%H$rF@$F8DJL$K%a%=%C%I$r8F$VI,MW$,$"$k!%(B
$B$3$l$G$O$;$C$+$/(B ThreadGroup $B$r;HMQ$7$F$$$F$b!$$=$N2ACM$,Dc$$!%(B
$B$^$?!$%M%C%H%o!<%/$r2p$7$F$$$k$J$I$G(B thread
$B$,=hM}ESCf$GNc30=*N;$9$k2DG=@-$,$"$j!$(B
$B$=$N$h$&$J>l9g$O$9$0$KBeBX(B thread $B$r5/F0$9$kI,MW$,$"$k$H$9$k$H!$(B
$B%7%9%F%`$,BZ$j$J$/F0:n$9$k$K$OB??t$N(B thread
$B$Nu67$r4F;k$7B3$1$kI,MW$,$"$k!%(B
$B8=:
$N(B Ruby $B$G$3$l$r9T$&$K$O(B polling
$B$G>uBV$rDI$&I,MW$,$"$j!$8zN($,0-$$(B
($B$$$D$I$N(B thread $B$,$I$&$$$&M}M3$G=*N;$9$k$+$o$+$i$J$$$N$G(B join
$B$G$OBT$F$J$$$?$a(B)$B!%(B
$B$"$k$$$O!$BT$D$Y$-(B thread $B$r;XDj$7$FJL(B thread $B$G(B warp
$B$9$k$3$H$G(B
$B=*N;=g$K(B serialize $B$9$kJ}K!(B ($BBP>](B thread
$B$NL@<($,I,MW$G$"$C$?$j!$(B
thread $B?t$,G\A}$9$k$3$H$K$J$kE@$,4r$7$/$J$$(B) $B$r<h$kI,MW$,$"$k!%(B
ThreadGroup
$B$N6/2=%W%i%s$G$O!$$=$&$7$?%1!<%9$G$N=hM}8zN(2~A1$b4^$a$k!%(B

$B$J$!$E:IU%i%$%V%i%j$N(B thwait (TheadsWait $B%/%i%9(B)
$B$,N`;w$7$?5!G=$r;}$DB8:_$@$,!$(B
$BF1%i%$%V%i%j$N5!G=$O!$K\Mh!$(BThreadGroup $B$,C4$&$Y$-$b$N$G$"$k!%(B
$B$=$N0UL#$G$O!$(BThreadsWait
$B$HF1$8%$%s%9%?%s%9%a%=%C%I$bMQ0U$7$F$
$/$Y$-$G$"$m$&!%(B
ThreadsWait $B$N%$%s%9%?%s%9%a%=%C%I72$O<!$NDL$j!%(B

ThreadsWait#all_waits
ThreadsWait#all_waits{|thread| …}
ThreadsWait#empty?
ThreadsWait#finished?
ThreadsWait#join(*threads)
ThreadsWait#join_nowait(*threads)
ThreadsWait#next_wait(nonblock = nil)
ThreadsWait#threads

ThreadsWait $B$H(B ThreadGroup $B$H$NBg$-$J0c$$$O!$(B
$B@8@.$5$l$?(B sub-thread $B$,<+F0E*$K4IM}2<$KCV$+$l$k$+$I$&$+$K$"$k!%(B
ThreadsWait $B$O!$(BThreadGroup $B2#CG$G(B thread
$B$rBT$?$M$P$J$i$J$$>l9g$H!$(B
$BJL$N(B ThreadGroup $B$r@8@.$7$F$^$H$a$k$3$H$,$G$-$J$$(B thread
$B72$rBT$?$M$P$J$i$J$$>l9g(B
$B$H$GM-8z@-$r0];}$9$k!%(B
$B8e<T$N$h$&$JNc$,K\Ev$KB8:_$9$k$+$OJ,$+$i$J$$$,!$>/$J$/$H$bA0<T$N$h$&$JNc$O$"$jF@$k!%(B

*** $BC1=c$J(B Thread $BA`:n%a%=%C%I$NITB-(B ***
$BFCDj$N(B ThreadGroup $B$K(B Thread $B$r@8@.$9$k$K$O!$(B
Thread $B$r@8@.$7$?>e$GBP>]$N(B ThreadGroup $B$K0\F0$9$k$7$+$J$+$C$?!%(B
$B$7$+$7$=$l$G$O(B ThreadGroup $B$r0\F0$9$kA0$K(B
Thread $B$N=hM}$,?J9T$7$F$7$^$&2DG=@-$,9b$/!$(B
$B$=$l$r2sHr$9$k$?$a$K(B Thread $B$r0lC6(B stop $B$7$F$*$$$F(B
$B0\F08e$K(B wakeup $B$9$kI,MW$,$"$C$?!%(B

$B$3$NLdBj$X$NBP:v$H$7$F!$(BThreadGroup#new_thread $B$rF3F~$9$k!%(B
$B<B9T$K$O!$8=:_$N(B ThreadGroup $B$G@8@.$7$?(B thread $B$r(B
$B%l%7!<%P$N(B ThreadGroup
$B$K0\F0$9$k8"8B$r;}$D$3$H$,I,MW$G$"$k$H$9$k!%(B

$B$=$NB>!$Nc$($P(B ThreadGroup $B$KB0$9$k(B Thread
$B$9$Y$F$N=*N;$rBT$D$h$&$J%a%=%C%I(B
ThreadGroup#join $B$N$h$&$K!$(BThreadGroup $B$r(B Thread
$B=89g$H$7$FA`:n$9$k$?$a$K(B
$BITB-$H;W$($k%a%=%C%I$rDI2C$9$k!%(B

*** ThreadGroup $B$N(B dominate ***
$B8=:_$N(B ThreadGroup $B$G$O!$(Benclose $B$5$l$?>l9g$K(B
$B30It$+$i(B Thread $B$rF3F~$9$k<jCJ$,$J$$!%(B
enclose $B$H$O$=$&$$$&$b$N$@$+$i$H$$$&OC$O$"$k$,!$(B
enclose $B$5$l$?(B ThreadGroup $B$r4F;k$9$k(B Thread (ThreadGroup)
$BB&$+$i$9$k$H!$(B
$B>/!9?45v$J$$@)Ls$G$"$k!%(B
$BNc$($P!$4F;kBP>]$N(B ThreadGroup $BFb$K4IM}MQ(B Thread
$B$NN`$,I,MW$H$J$j$&$k$J$i!$(B
enclose $B$9$kA0$K$=$&$7$?(B Thread $B$r@8@.$7$F$*$/I,MW$,$"$k!%(B
$B$^$?!$$b$72?$i$+$N%H%i%V%k$G4IM}MQ(B Thread
$B$,Mn$A$F$7$^$&$H2sI|$NJ}K!$,$J$$!%(B

$B$=$3$G!$(BThreadGroup $B4V$K(B dominate $B$H$$$&4X78$r5,Dj$9$k!%(B
$B$"$k(B ThreadGroup A $B$,JL$N(B ThreadGroup B $B$r(B dominate
$B$7$F$$$k$J$i$P!$(B
A $B$KB0$9$k(B Thread $B$O!$(BB $B$K!$$"$k$$$O(B B $B$+$i(B Thread
$B$r0\F0$5$;$k$3$H$,$G$-$k!%(B
$B$?$@$7!$(BB $B$@$1$G$J$/(B Thread $B$N0\F085(B/$B0\F0@h$K$b(B A
$B$,0\F08"8B$r;}$?$M$P$J$i$J$$!%(B
Thread $B$N0\F08"8B$r;}$D$N$O(B ThreadGroup $B$NA`:n8"8B$r;}$D>l9g$G!$(B

  • $BBP>]$,@)LsL5$7$N(B ThreadGroup
  • $BBP>]$,(B domanated $B$G!$<+?H$,BP>]$r(B dominate $B$7$F$$$k(B
    ThreadGroup $B$N(B Thread
    $B$N$$$:$l$+$N>l9g$G$"$k!%(B

dominate $B$7$F$$$k(B ThreadGroup A $B$H$N4X78$r=|$$$F$O!$(B
dominate $B$5$l$F$$$k(B ThreadGroup B $B$O(B enclose
$B$5$l$F$$$k>l9g$HF1$8@)Ls$r;}$D!%(B

$B$J$!$(Bdominated $B"(B enclosed $B"*(B frozen
$B$N4X78$O0lJ}DL9T$G$"$j!$(B
$B>uBVJQ998e$O85$KLa$9$3$H$O$G$-$J$$!%(B

*** Thread $B$,;}$D%"%/%;%98"8B(B ***
$B8=:_$N(B ThreadGroup $B$K$O!$(B
ThreadGroup $B4D6-$+$i$N(B Jail Break $B$rKI$0$?$a$N(B enclose
$B$H$$$&5!9=$,$"$k$,!$(B
enclose $B$5$l$?(B ThreadGroup $BFb$N(B Thread
$B$N8"8B$K$D$$$F$O$-$A$s$H$7$?5,Dj$,$J$$!%(B

ThreadGroup $B$r(B enclose $B$9$kL\E*$O!$(BThreadGroup
$B$K$h$C$FM?$($i$l$?J8L.$+$i(B
$BITMQ0U$KN%C&$7$F$7$^$o$J$$$h$&$K$H$$$&0BA4:v$N0UL#$b$"$k$,!$(B
$BFCDj$N(B Thread $B72$r?.MQ$G$-$J$$$H$$$&%1!<%9$b$"$k$@$m$&!%(B
$B$=$&9M$($k$H!$(Benclose $B$d(B freeze $B$5$l$?(B ThreadGroup $B$+$i(B
$BB>$N(B ThreadGroup $B$KB0$9$k(B Thread
$B$rA:n$9$k$3$H$OG'$a$k$Y$-$G$O$J$$$H8@$($k!%(B $B5U$K!$$=$&$7$?A:n$r5v$9$3$H$,$G$-$k$N$J$i!$(B
$B$o$6$o$6(B enclose $B$d(B freeze $B$r$9$kI,MW$OK3$7$$$H9M$($k!%(B

$B$h$C$F!$(Benclose $B$^$?$O(B freeze $B$5$l$?(B ThreadGroup $B$N(B
Thread $B$,!$(B
$B8"8B$N$J$$B>$N(B ThreadGroup $B$N(B Thread
$B$rA`:n$9$k$3$H$r6X;_$9$k$3$H$,K>$^$7$$!%(B
$B6qBNE*$K$O!$(BThread $B$N%$%s%9%?%s%9%a%=%C%I$NFb!$(B

[]=, abort_on_exception=, exit, kill, terminate,
priority=, raise, run, wakeup

$B$G$"$k(B ($B>uBV;2>H$O5v$9$,!$>uBVJQ99$O5v$5$J$$(B)$B!%(B
$B$7$+$7!$8_49@-$r<:$&$?$a$K$3$N@)Ls$rD>@\F3F~$9$k$3$H$OFq$7$$$@$m$&!%(B
$B$f$($K!$%G%U%)%k%H$G$O=>MhDL$j@)Ls$O$J$7$H$7$F$*$-!$(B
$B@)Ls$r@_Dj4IM}$9$k$?$a$N%a%=%C%I$H$7$F(B
ThreadGroup#lock, ThreadGroup#locked? $B$rF3F~$9$k!%(B
$B$3$N>l9g!$(Benclose $B$J$I$r$5$l$F$$$J$$(B ThreadGroup $B$K(B
$B@)Ls$rIUM?$9$k$3$H$b2DG=$G$O$"$k(B
($B%f!<%9%1!<%9$OK3$7$=$&$@$,!D(B)$B!%(B

*** ThreadGroup $B$N(B thread_queue ***
$BKAF,$G=R$Y$?$h$&$J(B polling $B$NLdBj$r2sHr$9$k$?$a$K!$(B
$B=*N;$7$?(B thread $B$r<u$1$H$k$?$a$N(B thread_queue $B$r(B ThreadGroup
$B$,;}$F$k$h$&$K$9$k!%(B
thread_queue $B$O!$=*N;$7$?(B Thread $B$r(B
$B=*N;=g$K$G$-$k$@$1Aa$/3Z$K=hM}$K$+$1$k$?$a$N5!9=$G$"$k!%(B

$B$b$A$m$s!$F0:n$5$;$k(B thread $B$N=hM}FbMF$K(B
$B=N;$r%l%]!<%H$9$k=hM}$r=q$$$F$$/$H$$$&J}K!$b$J$$$o$1$G$O$J$$$,!$(B
$B$=$l$r<BAu$9$k$H$J$k$H>/!9LLE]$G$"$m$&!%(B
$B=N;$7$?(B thread $B$,<+F0E$KFCDj$N(B queue $B$KDI2C$5$l$k$J$i(B
($B$3$N=hM}$O(B C $B%l%Y%k$G(B Coding $B$9$kI,MW$,$"$k(B)$B!$(B
$B4IM}B&$,$=$N(B queue $B$+$iFI$_=P$7$F<B9T$9$k=hM}$r=q$/$@$1$GNI$/!$(B
$BLLE]$JItJ,$r1#JC$9$k$3$H$,$G$-$k!%(B
$B4IM}BP>]$H$J$k$N$O(B Thread $B$N=89g$G$"$k$+$i!$(B
ThreadGroup $B$K$=$&$7$?(B queue $B$r;}$?$;$k$N$OBEEv$H8@$($k!%(B

thread_queue $B$O0l$D$N(B ThreadGroup $B$K$D$-0l$D$@$1$H$9$k!%(B
thread_queue $B$N%b!%I$O!$@5o=*N;!$Nc30=*N;$N$=$l$>$l$KBP$7!$(B
thread_queue $B$KDI2C$9$k(B/$B$7$J$$$N#2<oN`$r@_Dj$9$k!%(B
$B%G%U%)%k%H$O!V$$$:$l$bDI2C$7$J$$!W$G$"$k!%(B

$B%a%b%j>CHq$NGzH/$rHr$1$k$?$a!$%G%U%)%k%H$G$O(B thread_queue
$B$N%5%$%:$rM-8B$H$7!$(B
$BJ];}%5%$%:$rD6$($?>l9g$O8E$$(B Thread $B$+$i<N$F$k$3$H$H$9$k!%(B

thread_queue $B$N%"%/%;%9$K$O8"8B$,I,MW$G$"$k!%(B
$B<+$i$,@)Ls$r;}$?$J$$$+!$<+$i$,BP>]$N(B ThreadGroup $B$r(B dominate
$B$7$F$$$k>l9g$K8B$j!$(B
$BBP>]$N(B ThreadGroup $B$N(B thread_queue
$B$X$N%"%/%;%9$r5v$9$3$H$H$9$k!%(B

*** ThreadGroup $B$N8GM-%G!<%?(B ***
Thread $B$KJ8L.$rM?$($k$?$a$K$O(B ThreadGroup
$B$KJ8L.$r5,Dj$9$k%G!<%?$rJ];}$5$;$k!%(B
$B$b$7?7$7$$(B Thread $B$,@8@.$5$l$F$b!$<+F0E*$K8=:_$N(B ThreadGroup
$B$K=jB0$9$k$?$a!$(B
ThreadGroup $B$K$h$kJ8L.$,J];}$5$l$k(B (ThreadGroup
$B$r0\F0$9$l$P!$J8L.$bJQ99$5$l$k(B)$B!%(B

$B$3$l$^$G$O(B Thread $B$N$h$&$K(B ThreadGroup
$B$K8GM-%G!<%?$r;}$?$;$k$?$a$N%a%=%C%I$,(B
$BDj5A$5$l$F$O$$$J$+$C$?$?$a!$(BThread
$B%/%i%9F1MM$K8GM-%G!<%?$r07$&%a%=%C%I$rDI2C$9$k!%(B

*** $B%a%=%C%I0lMw(B ***
ThreadGroup.new()
ThreadGroup.new(hash)
ThreadGroup $B8GM-%G!<%?$r@_Dj$9$k0z?t$rDI2C(B
current ThreadGroup $B$r?F(B ThreadGroup $B$H$7$FJ];}$9$k(B

ThreadGroup.current
Thread.current.group $B$KF1$8(B

ThreadGroup.queueing
current thread $B$r$=$N(B threadgroup $B$N(B thread queue $B$KF~$l$k(B
thread queue $B$X$NEjF~$,5v2D$5$l$F$$$J$1$l$P!$Nc30$r@8$8$k(B

ThreadGroup#add(thread)
ThreadGroup#add(*threads)
$BJ#?t$N(B thread $B$r0lEY$K<uIU$G$-$k$h$&$K!$0z?t%Q%?!<%s$r3HD%(B
max_threads $B$rD62a$9$k>l9g$O!$Nc30$r@8$8$k(B

ThreadGroup#<<(thread)
ThreadGroup#add(thread) $B$KF1$8(B

ThreadGroup#list
$B=>Mh$HF1$8(B

ThreadGroup#threads
ThreadsWait $B$HF1Ey$N%a%=%C%I$rB7$($kL\E*$GDI2C$9$k%a%=%C%I(B
$B<BBN$O(B ThreadGroup#list

ThreadGroup#max_threads
ThreadGroup#max_threads=(size)
ThreadGroup$B$K4^$a$k$3$H$,2DG=$J:GBg(B thread
$B?t$r@_Dj(B/$B;2>H$9$k(B
$BCM(B 0 $B$r@_Dj$7$?>l9g$OL5@)8B$H$J$k(B
$B@)8B$rD62a$9$k$h$&$J=hM}$,<B9T$5$l$?>l9g$ONc30$r@8$8$k(B
$B@Dj;~$K$9$G$K(B ThreadGroup $B$KB8:$9$k(B thread
$B?t$h$j$b>/$J$$CM$r(B
$B@_Dj$7$h$&$H$7$?>l9g!$CM$r;XDjDL$j$K@_Dj$7$?>e$GNc30$r@8$8$k(B

ThreadGroup#size
ThreadGroup#length
$B8F$s$@;~E@$G(BThreadGroup$B$KB0$9$k(Bthread$B$N?t$rJV$9(B

ThreadGroup#enclose
ThreadGroup#enclosed?
$B=>Mh$HF1$8(B
$B$?$@$7!$(Bdominated $B$G$"$l$P(B enclosed? $B$O(B true $B$H$J$k(B

ThreadGroup#lock
ThreadGroup#locked?
$BB>$N(B ThreadGroup $B$KB0$9$k(B Thread
$B$NA`:n@)Ls$N@_Dj$H>uBV;2>H(B

ThreadGroup#[]
ThreadGroup#[]=
ThreadGroup#key?(key)
ThreadGroup#keys
ThreadGroup $B8GM-%G!<%?$X$N%"%/%;%9(B
$B8=:_$N(B ThreadGroup
$B$,%l%7!<%P$NA:n8"8B$r;}$?$J$$>l9g$K$O;2>H!&JQ99$OIT5v2D(B ( $B8=:_$N(B ThreadGroup == $B%l%7!<%P$N>l9g$OA:n8"8B$"$j(B )

ThreadGroup#new_thread(){ … }
$B%l%7!<%P$N(B ThreadGroup $B$K?7$7$$(B thread $B$r@8@.(B
(Thread.new$B$HF1$8(B)
$B0z?t$O(B Thead#new $B$HF1$8(B
$B<B9T$O!$8=:_$N(B ThreadGroup $B$+$i%l%7!<%P$X$N(B Thread
$B0\F08"8B$r;}$D$3$H$,I,MW(B

ThreadGroup#start_thread(){ … }
ThreadGroup#fork_thread(){ … }
$B%l%7!<%P$N(B ThreadGroup $B$K?7$7$$(B thread $B$r@8@.(B
(Thread.{start,fork}$B$HF1$8(B)
$B0z?t$O(B Thead#new $B$HF1$8(B
ThreadGroup#new_thread $B$H0c$C$F(B Thread#initialize $B$r8F$P$J$$(B
$B<B9T$O!$8=:_$N(B ThreadGroup $B$+$i%l%7!<%P$X$N(B Thread
$B0\F08"8B$r;}$D$3$H$,I,MW(B

ThreadGroup#new_thread_of(klass,…){ … }
ThreadGroup#start_thread_of(klass,…){ … }
ThreadGroup#fork_thread_of(klass,…){ … }
$B@8@.$9$k(B thread $B$,(B klass $B%/%i%9$N$b$N$G$"$k$3$H$r=|$$$F$O(B
new_thread $BEy$HF1$8(B
$B$?$@$7!$(Bklass $B$O(B Thread
$B%/%i%9$N%5%V%/%i%9$G$J$1$l$P$J$i$J$$(B

ThreadGroup#dominate(threadgroup)
$B%l%7!<%P$,0z?t$N(B threadgroup $B$r(B dominate $B$9$k$h$&$K$9$k(B
$B0z?t$N(B threadgroup $B$,(B enclose $B$5$l$F$$$J$1$l$P(B enclose
$B$5$l$k(B
$B8=:_$N(B ThreadGroup
$B$,%l%7!<%P$H0z?t$H$NN>J}$KA`:n8"8B$r;}$?$J$1$l$PNc30$rH/@8(B
$B$b$7!$0z?t$N(B threadgroup == $B%l%7!<%P$J$i!$Nc30$rH/@8$9$k(B

ThreadGroup#dominate?(threadgroup)
$B%l%7!<%P$,(B threadgroup $B$r(B dominate $B$7$F$$$k$J$i(B true
$B$rJV$9(B
$B8=:$N(B ThreadGroup
$B$,%l%7!<%P$H0z?t$H$NA`:n8"8B$r;}$?$J$$>l9g$K$ONc30$H$J$k(B
$B8=:
$N(B ThreadGroup == $B0z?t$N>l9g!$(Benclosed
$B0J>e$G$"$l$P8"8B$J$7$H$9$k(B
( enclosed $B0J>e$N(B ThreadGroup $B$,<+J,$N(B dominate
$B>uBV$rD4$Y$k$N$r6X;_$9$k$?$a(B )

ThreadGroup#dominated?
$B%l%7!<%P$r(B dominate $B$7$F$$$k(B ThreadGroup $B$rJV$9(B
$B8=:$N(B ThreadGroup
$B$,%l%7!<%P$NA`:n8"8B$r;}$?$J$$>l9g$K$ONc30$H$J$k(B
$B8=:
$N(B ThreadGroup == $B%l%7!<%P$N>l9g!$(Benclosed
$B0J>e$G$"$l$P8"8B$J$7$H$9$k(B
( enclosed $B0J>e$N(B ThreadGroup $B$,<+J,$N(B dominate
$B>uBV$rD4$Y$k$N$r6X;_$9$k$?$a(B )

ThreadGroup#make_local_space!
$B%l%7!<%P$K(B local space $B$r:n@.$9$k(B
$B%l%7!<%P$,$9$G$K8GM-$N(B local space $B$r;}$D>l9g$O2?$b$;$:$KLa$k(B
$B%l%7!<%P$,7Q>5$5$l$?(B local space $B$r;}$D>l9g$O!$(B
$B$=$l$r%3%T!<$7$?$b$N$r8GM-$N(B local space $B$H$7$F@_Dj$9$k(B
$B0lEY@_Dj$5$l$?(B local space $B$r=|5n$9$k$3$H$O$G$-$J$$(B
local space $B$r;}$D(B threadgroup $B$N(B thread $B$,?7$?$K(B
threadgroup $B$r@8@.$7$?>l9g!$(B
$B$=$N(B local space $B$,?7$?$J(B threadgroup $B$K7Q>5(B ($B6&M-(B)
$B$5$l$k(B

ThreadGroup#has_local_space?
$B%l%7!<%P$,(B local space $B$r;}$D$+$I$&$+$r??56CM$GJV$9(B
$B??$rJV$9>l9g!$$=$N(B local space
$B$,8GM-$N$b$N$+7Q>5$5$l$F$$$k$b$N$+$OLd$o$J$$(B

ThreadGroup#join(exception=false)
ThreadGroup#join(limit, exception=false))
ThreadGroup $B$N$9$Y$F$N(B thread $B$,=*N;$9$k$N$rBT$D(B
$B<!9`$N(B ThreadsWait
$B$HF1Ey$N5!G=$r;}$?$;$k$?$a$N=q<0$b;2>H$9$k$3$H(B
$B0z?t(B limit ($BICC10L$N?tCM(B) $B$,;XDj$5$l$F$$$l$P!$$=$N;~4V$G(B
timeout $B$9$k(B
join $B$r8F$s$@8e$K@8@.$5$l$?(B thread $B$G$"$C$F$b=*N;$rBT$D(B
$B=*N;$7$?(B thread $B$rG[Ns$K$7$FJV$9(B
$B0z?t(B exception $B$K$D$$$F$O!$(B
nil $B$G$"$k$H$-$O!$Nc30$r@8$8$?(B thread $B$OGK4~$7$F$=$l0J30$N(B
thread $B$N$_$rJV$9(B
true $B$G$"$k$H$-$O!$Nc30$NM-L5$K8B$i$:$9$Y$F$N(B thread
$B$rLa$jCM$NG[Ns$K4^$a$k!%(B
false $B$N$H$-$O!$Nc30$r@8$8$?(B thread
$B$K=P2q$C$?;~E@$G$=$NNc30$rH/@8$5$;$k(B

ThreadGroup#join(thread, …, thread, exception=false)
ThreadGroup#join(thread, …, thread, limit, exception=false))
ThreadsWait
$B$HF1Ey$N%a%=%C%I$rB7$($kL\E*$GDI2C$9$k0z?t%P%j%(!<%7%g%s(B
$B0z?t$N:G:872$,(B thread $B%*%V%8%’%/%H$G$"$k>l9g!$(B
$B$=$l$i$N(B thread $B$r$9$Y$F%l%7!<%P$G$"$k(B threadgroup $B$K(B add
$B$7$?8e!$(B
$B;D$j$N0z?t$r;H$C$F(B ThreadGroup#join $B$r8F$V!%(B

ThreadGroup#join_nowait(threads)
ThreadsWait $B$HF1Ey$N%a%=%C%I$rB7$($kL\E
$GDI2C$9$k%a%=%C%I(B
$B<BBN$O(B ThreadGroup#add(*threads)

ThreadGroup#wait_queueing()
ThreadGroup#wait_queueing(*threads)
$B;XDj$5$l$?(B thread $B72$N$9$Y$F$,(B threadqueue $B$KF~$k$N$rBT$D(B
thread queue $B$X$NEjF~5v2D$,$I$N<o$N(B thread
$B$K$b$J$5$l$F$$$J$1$l$P!$Nc30$r@8$8$k(B
$B0z?t;XDj$,$J$$>l9g!$8F$s$@;~E@$G(B threadgroup $B$KB0$9$k$9$Y$F$N(B
thread $B$rBP>]$H$9$k(B
queueing $BBT$A$NBP>]$H$5$l$?(B thread $B$9$Y$F$rG[Ns$K$7$FJV$9(B

ThreadGroup#values(exceptions=false)
$B$9$Y$F$N(B thread $B$NLa$jCM$rG[Ns$K$7$FJV$9(B
$BCM$H(B thread $B$H$NBP1~$,<h$l$J$$$N$G!$CM$@$1$,I,MW$J>l9g$KMQ$$$k(B
thread $B$H$NBP1~$,I,MW$J$i!$(Bjoin $B$GF@$?(B thread
$B$NG[Ns$KBP$7$F(B each $B$9$k$3$H(B
$B0z?t$,(B nil $B$G$"$k$H$-$O!$Nc30$r@8$8$?(B thread
$B$OGK4~$7$F$=$l0J30$NLa$jCM$N$_$rJV$9(B
$B0z?t$,(B true
$B$G$"$k$H$-$O!$Nc30$ONc30%*%V%8%’%/%H$H$7$FLa$jCM$NG[Ns$K4^$a$k!%(B
$B0z?t$,(B false $B$N$H$-$O!$Nc30$r@8$8$?(B thread
$B$K=P2q$C$?;~E@$G$=$NNc30$rH/@8$5$;$k(B

ThreadGroup#exit
ThreadGroup#kill
ThreadGroup#terminate
ThreadGroup $B$N$9$Y$F$N(B thread $B$r(B terminate $B$9$k(B
kill $B$r8F$s$@8e$K@8@.$5$l$?(B thread $B$G$"$C$F$b(B terminate
$B$9$k(B
$B<BBN$O$3$s$J46$8(B

current = Thread.current
Thread.exclusive do
until((lst = self.list - current).empty?) do
lst.each {|th| th.kill}
end
end
current.kill if current.group == self

ThreadGroup#each{|th| … }
$B8F$s$@;~E@$G(B ThreadGroup $B$K4^$^$l$k$9$Y$F$N(B thread
$B$K$D$$$F7+$jJV$9(B
threadgroup.list.each{|th| … } $B$HF1Ey(B

ThreadGroup#each_queueing{|th| … }
threadqueue $B$KF~$l$i$l$?(B thread
$B$N$=$l$>$l$KBP$7$F%V%m%C%/$r<B9T$9$k(B
thread queue $B$rMxMQ$9$k$?$a!$BP>](B thread $B$O(B thread queue
$B$N(B mode $B$K0MB8$9$k(B
thread queue $B$X$NEjF~5v2D$,$I$N<o$N(B thread
$B$K$b$J$5$l$F$$$J$1$l$P!$Nc30$r@8$8$k(B
ThreadGroup $B$KB0$9$k(B thread $B$,B8:_$7$J$/$J$l$P=*N;$9$k(B

ThreadGroup#all_waits
ThreadGroup#all_waits{|th| … }
ThreadsWait $B$HF1Ey$N%a%=%C%I$rB7$($kL\E*$GDI2C$9$k%a%=%C%I(B
$B%V%m%C%/$rM?$($i$l$J$$;~$O(B ThreadGroup#join $B$HF1$8(B
$B%V%m%C%/$rM?$($i$l$?;~$O(B ThreadGroup#each_join $B$HF1$8(B

ThreadGroup#thread_queue_pop(non_block=false)
thread queue $B$+$i=*N;$7$?(B thread $B$r0l$D<h$j=P$9(B
thread queue $B$X$NEjF~5v2D$,$I$N<o$N(B thread
$B$K$b$J$5$l$F$$$J$1$l$P!$Nc30$r@8$8$k(B

ThreadGroup#set_thread_queue_mode(succeed=false,exception=false,queueing=false)
$B=*N;$7$?(B thread $B$rC_$($k(B thread queue $B$N%b!<%I$N@Dj(B
$B@5>o=*N;!$Nc30=*N;!$(Bqueueing $B$N$=$l$>$l$KBP$7!$(Bthread
$B$rC
$($k$+$r??56CM$G@_Dj$9$k(B

ThreadGroup#get_thread_queue_mode
$B=*N;$7$?(B thread $B$rC_$($k(B thread queue $B$N%b!<%I$N;2>H(B
thread $B$rC_$($k$+H]$+$N??56CM$r(B [succeed, exception, queueing]
$B$NG[Ns$GJV$9(B

ThreadGroup#thread_queue_length
ThreadGroup#thread_queue_length=(len)
ThreadGroup#thread_queue_limit
ThreadGroup#thread_queue_limit=(len)
thread queue $B$N:GBgD9$r;2>H!&@_Dj$9$k(B
thread $B?t$NGzH/$rKI$0$?$a$N$b$N(B
$B:GBgD9$rD6$($k>l9g$O8E$$(B thread $B$+$i<N$F$i$l$k(B
$B%G%U%)%k%H$ND9$5$O!$G[Ns$N%G%U%)%k%HD9$5$HF1$8(B 16 $B$H$7$F$*$/(B

ThreadGroup#thread_queue_empty?
$B=*N;$7$?(B thread $B$rC_$($k(B thread queue
$B$N$,6u$+$I$&$+$rD4$Y$k(B
queue $B$,6u$G$"$l$P(B true $B$rJV$9(B

ThreadGroup#finished?
ThreadsWait $B$HF1Ey$N%a%=%C%I$rB7$($kL\E*$GDI2C$9$k%a%=%C%I(B
$B<BBN$O(B ! threadgroup.thread_queue_empty?

ThreadGroup#next_wait
ThreadsWait $B$HF1Ey$N%a%=%C%I$rB7$($kL\E*$GDI2C$9$k%a%=%C%I(B
$B<BBN$O(B ThreadGroup#thread_queue_pop $B$HF1$8(B

ThreadGroup#abort_on_exception
ThreadGroup#abort_on_exception=(state)
TreadGroup $BFb$N(B thread
$B$G$NNc30H/@8;~$K%$%s%?%W%j%?<+BN$r=*N;$5$;$k$+H]$+(B

ThreadGroup#raise
$B8=:_(B ThreadGroup $B$K=jB0$9$k$9$Y$F$N(B thread
$B$KNc30$rH/@8$5$;$k(B
$B?7$?$K@8@.$5$l$?(B thread
$B$K$^$GNc30$rH/@8$5$;$kI,MW$O$J$5$=$&$J$N$G!"(B
$B<BBN$O(B Thread.exclusive{threadgroup.list.each{|th| th.raise(…)}}
$B$H$9$k(B

ThreadGroup#alive?
$B8=:(B ThreadGroup $B$K=jB0$9$k(B thread
$B$G@8$-$F$$$k$b$N$,B8:
$9$l$P(B true $B$rJV$9(B

ThreadGroup#empty?
ThreadsWait $B$HF1Ey$N%a%=%C%I$rB7$($kL\E*$GDI2C$9$k%a%=%C%I(B
$B8=:(B ThreadGroup $B$K=jB0$9$k(B thread $B$,B8:$7$J$1$l$P(B true
$B<BBN$O(B threadgroup.list.empty? $B$H$9$k(B

ThreadGroup#wakeup
$B8=:_(B ThreadGroup $B$K=jB0$9$k(B thread $B$N$9$Y$F$r5/$3$9(B
$B<BBN$OC1=c$K(B Thread.exclusive{threadgroup.list.each{|th|
th.wakeup}} $B$H$9$k(B

*** ThreadGroup $B$K$ODj5A$7$J$$M=Dj$N%a%=%C%I(B ***
Thread $B$K$"$k%a%=%C%I$NFb!$0J2<$O(B ThreadGroup
$B$G$N5!G=Dj5A$,Fq$7$$$N$G(B
$BF3F~$7$J$$M=Dj$G$"$k!%(B

ThreadGroup#value
$BJ#?t$N(B Thread $B$,BP>]$H$J$k$N$G!$(BThreadGroup#values $B$GDj5A(B

ThreadGroup#run
$B8=:(B ThreadGroup $B$K=jB0$9$k(B thread $B$N$9$Y$F$r5/$3$9(B
wakeup $B$O0UL#$,$"$k$H;W$&$,!$(Brun $B$O5?Ld(B
($B$I$l$K@)8f$r0$9$Y$-$+$,5,DjITG=(B)
$B8=:
$N(B thread list $B$K=g<!(B run
$B$r$+$1$k$H$$$&7A$O$"$jF@$k$,!%!%!%(B

ThreadGroup#priority
ThreadGroup#priority=
$B8=:_(B ThreadGroup $B$K=jB0$9$k(B thread
$B$N$9$Y$F$KBP$7$F@_Dj$9$k!%(B
thread $B$4$H$K0[$J$k2DG=@-$,9b$$$N$G!$;2>H$OIT2D!%(B

============================================================================

$B:G=i$K7+$jJV$7$F$*$/$N$G$9$,(BThreadPool$B$r6/2=$7$h$&$H$$$&$3$H<+BN$K$O$`$7(B
$B$m;?@.$G$9!"$?$@!"$I$N8~$-$K8~$+$C$F6/2=$9$k$N$+$,$h$/J,$+$i$J$$!#(B

$B$J$s$K$G$b;H$($^$9$OBgDq$N>l9g!"$J$s$K$b;H$($^$;$s$h!#(B

(06/28/2011 03:15 PM), Hidetoshi NAGAI wrote:

$B2a5n$K<c43$ND4::$r9T$C$?7k2L!"(BThread$B$rB+$K$7$FA`:n$7$?$$$H$$$&MQES$K$O(B
real world examples$B$,>/$J$9$.$F!"$$$^$$$A$G$9!#(B

$B4pK\E*$K$OB+$M$k$b$N$G$7$g$&$M!%(B
$B$3$l$^$G$O5!G=$,>/$J$9$.$F!$(Bsub thread $B$,<+F0E*$K4^$^$l$k$3$H$r=|$-!$(B
thread $B$r(B array $B$KF~$l$F4IM}$9$k$N$H$?$$$7$FJQ$o$i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$B$N>uBVJQ2=$K9b$$B(1~@-$r;}$?$5$;$k$?$a$K$O(B
polling $B$7$?$j!$BP>](B thread $B$4$H$K#18D$N@lMQ4F;k(B thread $B$rMQ0U$7$?$j(B
$B$9$kI,MW$,$"$j$^$9!%(B

$B$3$l$O$=$NDL$j$H;W$$$^$9!#(B

ThreadGroup $B%*%V%8%’%/%H$K;}$?$;$h$&$H$9$k(B thread_queue $B$O!$(B
thread $B72$N4F;kG=NO$N6/2=$r?^$k$H$$$&0UL#9g$$$,$"$j$^$9!%(B
thread pool $B%3%s%H%m!<%k$N<gF38"$r4F;kB&$K0$9$3$H$,2DG=$H$J$j$^$9!%(B
$BNc$($P(B thread $B72$,=hM}G=NO:9$N$"$kJL%^%7%s$K=hM}0MMj$r$9$k>l9g$G$b(B
$B3F(B thread $B$,=hM}40N;$KMW$7$?;~4V$r4F;k$70W$/$J$j$^$9$+$i!$(B
$B%9%1%8%e!<%j%s%0$b$h$jeLL)$K$G$-$k$+$b$7$l$^$;$s!%(B

$B$3$l$OK\Ev$K(BThreadGroup$B$rMQ$$$F<B8=$9$k5!G=$G$9$+(B?
$B$?$H$($P%9%l%C%I$,=hM}$KMW$7$?;~4V$r$I$3$+$K;}$C$F$*$/$H$9$l$P!“EvA3$=$N(B
$B%9%l%C%I<+?.$,CN$C$F$$$k$N$,<+A3$H;W$$$^$;$s$+(B?
$B$J$<(BThreadGroup$B$r$o$6$o(B
$B$6MQ0U$9$kI,MW$,$”$k$N$G$9(B?

$B<+J,$G(B thread_queue $B$r:n$C$F;w$?$3$H$r<B8=$9$k$3$H$b$G$-$^$9$,!$(B
thread_queue $B$X$NEjF~$r(B ruby $BK\BN$N(B thread $B4IM}$KAH$_F~$l$k$3$H$G!$(B
$BM=4|$;$L(B trouble $B$GMn$A$?(B thread
$B$G$bAa$/$KDc%3%9%H$G=&$($k$H;W$$$^$9!%(B

$B$3$l$O%-%e!<$r:n$k$J$i$H$$$&A0Ds$G!"@5$7$$$G$7$g$&!#(B

$B4{B8$N%/%i%9$KBP$9$k%a%=%C%IDI2C$b$7$P$7$P9T$o$l$^$9$,!$(B
$B$3$l$b%0%m!<%P%k$JJQ99$K$J$j$^$9$+$i6X;_$5$l$k$Y$-$b$N$H$J$j$^$9!%(B
safe level $B$NLdBj0J30$N%1!<%9$G$b!$Dj5A$,43>D$79g$&%i%$%V%i%jEy$r(B
$BF1;~$K;H$$$?$$$H$$$&>l9g$bF1MM$NLdBj$r4^$s$G$$$^$9!%(B

$B$?$H$($P;w$?$h$&$JLdBj0U<1$H$7$F(Bclassbox$B$H$+8F$P$l$k$b$N$,$"$C$F!"$9$G$K(B
trunk$B$K$O(BModule#mix$B$H$$$&5!G=$,F~$C$F$$$k$o$1$G$9$,!"$4B8CN$G$7$?$+(B?
$B%a(B
$B%=%C%I$N2D;k@-$NJQ99$r(BModule$B$G<B8=$9$k$H$$$&$N$O$-$o$a$F<+A3$JH/A[$G$9!#(B
Module$B$O$=$N$?$a$N$b$N$G$9$+$i$M!#$7$+$k$K!"(BModule#mix$B$G$O$J$/!"(B
ThreadGroup$B$K5!G=$rDI2C$9$k!"$J$<$G$9$+!#$J$<(BModule$B$G$O$J$$$N$G$9$+!#(B

$B$3$l$i$NLdBj$N$9$Y$F$r(B safe level $B$N3HD%$GBP=h$G$-$k$H$O;W$($^$;$s!%(B
$B2>$K(B safe level $B$+$i$N%"%W%m!<%A$G2r7h$r?^$k$H$7$F$b!$(B
ThreadGroup $B$,4IM}C10L$H$J$C$F(B make_local_space! $B$N$h$&$J$b$N$,(B
$BI,MW$K$J$k$@$m$&$HM=A[$7$^$9!%(B

$B$J$<$G$9$+!#(B

$B$J$i$P!$(Bsafe level $B$HL54X78$KM-8z$K;H$$$&$k(B make_local_space!
$B$r<BAu$7!$(B
$B$=$l$HAH$_9g$o$;$F(B safe level
$B$N5!G=6/2=$r9M$($k$N$bIT<+A3$H$O;W$($^$;$s!%(B

$B$$$$$(IT<+A3$G$9!#$J$<(BThreadGroup$B$K$=$N$h$&$J5!G=$,I,MW$G$9$+(B?

$B1J0f!wCNG=!%6e9)Bg$G$9!%(B

From: KOSAKI Motohiro [email protected]
Subject: [ruby-dev:43979] Re: ThreadGroup#make_local_space!
Date: Tue, 28 Jun 2011 16:07:56 +0900
Message-ID: [email protected]

$B<c43$^$H$^$C$F$$$J$$46$,$“$j$^$9$,!”$o$?$7$,:#$$$@$$$F$$$k0u>]$r%@%s%W(B
$B$5$;$F$/$@$5$$!#$I$&$b5DO@$,?J$s$G$$$J$$$H$$$&$+!"$3$N$^$^J|CV$7$F$$$F$b(B

$B%^!<%8$9$kN.$l$K$$$+$J$$$s$8$c$J$$$+$J!#$H$$$&5?G0$,$L$0$($J$$$H$$$$$^$9$+!#!#(B

$BH?1~$NK3$7$5$O!$3’$5$s$,8=>u$KFC$KITK~$r;}$C$F$$$J$$(B
($BB?J,!$;H$C$F$$$J$$$N$G:$$C$F$$$J$$(B)
$B$3$H$rJ*8l$C$F$$$k$N$@$H;W$$$^$9!%(B

$B$?$H$($P(BJava$B$@$H!“:#$N(BRuby$B$HF1$8$/Hs>o$K%W%”$J(BThreadGroup$B%/%i%9$,$“$j$^$9$,!”(B

$B8=>u$N(BThreadGroup$B$r@Q6KE*$K;H$C$F$k%1!<%9$b!"$=$l$r3HD%$7$?$$$H;W$C$F$$$k(B

$B%f!<%6%0%k!<%W$b$"$s$^$j?4Ev$?$j$,$J$+$C$?$j$^$7$^$9!#(B

$B$J$N$G!"(BJava$B$G$OITMW$@$1$I(BRuby$B$G$OI,MW$H$J$kM}M3$O$J$s$@$m$&!#$H$$$&$N$,(B

$B:G=i$KJz$$$?5?Ld$G$9!#(B

$B<B:]$KITJX$K46$8$F$$$?$3$H$,H/C<$G$O$"$k$N$G$9$,!$(B
$B;d$,JQ$j<T$C$F$3$H$J$s$G$7$g$&$M$'!%!%!%(B(^_^;

$B<!$K$?$$$X$s0d48$J$,$i(BRuby$B$K$*$$$F(Bthread
$BJBNs$NL$Mh$O0E$$$s$8$c$J$$$+$H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K$J$kItJ,$O$"$j$=$&$J$N$G$9$,!$:#$O2?$H$b8@$($^$;$s!%(B

$B4{B8$N5!G=$NHO0O$G<BAu$9$k$3$H$P$+$j$r9M$($F$-$?$?$a!$(B

$B5U$O$9$0$K$O;W$$IU$-$^$;$s!%$4$a$s$J$5$$!%(B

$B%3%s%F%J$H$J$k%&%#%8%'%C%H$K(B thread group
$B$r3d$jEv$F$F!D$H$$$&4k$_$b(B
$B$J$/$O$J$$$G$9$,!$$^$@[0$m$2$J%W%i%s$G$9!%(B

$B$^$D$b$H(B $B$f$-$R$m$G$9(B

In message “Re: [ruby-dev:43978] Re: ThreadGroup#make_local_space!”
on Tue, 28 Jun 2011 15:15:07 +0900, Hidetoshi NAGAI
[email protected] writes:

|> $B2a5n$K<c43$ND4::$r9T$C$?7k2L!“(BThread$B$rB+$K$7$FA`:n$7$?$$$H$$$&MQES$K$O(B
|> real world examples$B$,>/$J$9$.$F!”$$$^$$$A$G$9!#(B
|
|$B4pK\E*$K$OB+$M$k$b$N$G$7$g$&$M!%(B
|$B$3$l$^$G$O5!G=$,>/$J$9$.$F!$(Bsub thread $B$,<+F0E*$K4^$^$l$k$3$H$r=|$-!$(B
|thread $B$r(B array $B$KF~$l$F4IM}$9$k$N$H$?$$$7$FJQ$o$i$J$+$C$?!$(B
|$B$=$l$f$(!$$o$6$o$6;H$&5$$K$b$J$i$J$+$C$?$H$$$&$h$&$K;W$$$^$9!%(B

$B$$$A$$&(BThreadGroup$B$O!“$”$k%9%l%C%I$,:n$C$?;R%9%l%C%I$r$R$H$^(B
$B$H$a$K$7$F$
$$$F!"0lEY$K6/@)=*N;$5$;$k$h$&$J%f!<%9%1!<%9$rG0(B
$BF,$KCV$$$F@_7W$7$^$7$?!#(B

|$B4X?tE*%a%=%C%I$b;H$C$F$$$k$h$&$JIaDL$N(B Ruby $B%9%/%j%W%H$r(B
|$B4D6-1x@w$9$k$3$H$J$/$=$N$^$^F0$+$;$k4D6-$,M_$7$$$H9M$($F$$$^$9!%(B

$B$=$l$r(BThreadGroup$B$G<B8=$G$-$k$+!“$9$k$Y$-$+!”$K$D$$$F$O$A$g$C(B
$B$H5?G0$r;}$C$F$$$^$9!#8@8l%l%Y%k$G2r7h$5$l$k$Y$-$h$&$J5$$,$7(B
$B$^$9$7!#(B

|$B$3$l$i$NLdBj$N$9$Y$F$r(B safe level $B$N3HD%$GBP=h$G$-$k$H$O;W$($^$;$s!%(B
|$B2>$K(B safe level $B$+$i$N%"%W%m!<%A$G2r7h$r?^$k$H$7$F$b!$(B
|ThreadGroup $B$,4IM}C10L$H$J$C$F(B make_local_space! $B$N$h$&$J$b$N$,(B
|$BI,MW$K$J$k$@$m$&$HM=A[$7$^$9!%(B

$B$=$NE@$OH]Dj$7$^$;$s$,!“(Bmake_local_space$B$,K>$^$7$$2r$+$H$$$&(B
$B$H<+?.$,$”$j$^$;$s!#(B

                            $B$^$D$b$H(B $B$f$-$R$m(B /:|)

$B1J0f!wCNG=!%6e9)Bg$G$9!%(B

From: Urabe S. [email protected]
Subject: [ruby-dev:43983] Re: ThreadGroup#make_local_space!
Date: Tue, 28 Jun 2011 21:25:21 +0900
Message-ID: [email protected]

$B4pK\E*$K$OB+$M$k$b$N$G$7$g$&$M!%(B
$B$3$l$^$G$O5!G=$,>/$J$9$.$F!$(Bsub thread $B$,<+F0E*$K4^$^$l$k$3$H$r=|$-!$(B
thread $B$r(B array $B$KF~$l$F4IM}$9$k$N$H$?$$$7$FJQ$o$i$J$+$C$?!$(B
$B$=$l$f$(!$$o$6$o$6;H$&5$$K$b$J$i$J$+$C$?$H$$$&$h$&$K;W$$$^$9!%(B

$B$$$$$(!#(BThread$B$rB+$M$F;H$&$H$$$&LL$G$O$`$7$m8=:_$N(BThreadGroup$B$OG[Ns$h$j(B

$B$bB`2=$7$F$$j!"@Q6KE$K4wHr$5$l$^$9!#>/$J$/$H$bB+$M$?$O$:$N%9%l%C%I$,CN(B
$B$i$L4V$K$I$C$+$K9T$C$F$7$^$&$h$&$J$b$N$r!";d$N463P$G$OB+$M$?$H$O8@$$$^$;$s!#(B

ThreadGroup#enclose $B$OB+$+$iF($5$J$$$?$a$N$b$N$G$9$h$M!%(B
$B=N;$7$?(B thread $B$,>!<j$K>C$($k$3$H$r$$C$7$c$C$F$$$k$N$G$“$l$P!$(B
$B$=$l$OMxE@$G$b$”$j7gE@$G$b$“$k$G$7$g$&!%(B
$B$3$l$^$G$O4F;kMQ$N(B thread $B$rMQ0U$9$k$J$I$7$J$$8B$j(B
$B=*N;$7$?(B thread $B$r$&$^$/Ja3M$9$k<jCJ$,$”$j$^$;$s$G$7$?$,!$(B
thread_queue $B$rMQ$$$l$P!$(Bthread $B$N%j%9%H$r%A%‘%C%/$7$J$/$F$b(B
thread $B$N=*N;=g$K=hM}$G$-$^$9!%(B
$BG[Ns$N3F(B thread $B$r(B join $B$GBT$D>l9g$O!$(B
$BC1=c$K$O$=$NG[Ns$N(B order $B$G$7$+=hM}$G$-$^$;$s!%(B
$B3N$+$K=*N;$7$?(B thread
$B$G$b$I$3$+$K>C$($k$3$H$J$/G[Ns$K;D$j$D$E$1$^$9$,!$(B
$B;`$s$@(B thread
$B$N:F3h@-2=$,$G$-$J$$0J>e!$=*N;%A%’%C%/8e$OITMW$J$O$:$G!$(B
$B=N;$7$?$b$N$r$$$D$^$G$bJ];}$7$F$$+$M$P$J$i$J$$M}M3$,$o$+$j$^$;$s!%(B

ThreadGroup $B$N5!G=6/2=$K$h$j!$(BThreadGroup $B$H$$$&$b$N$N3hMQ$NI}$r9-$2!$(B
$B$R$$$F$O(B thread
$B3hMQ%W%m%0%i%_%s%0$NI}$b9-$2$i$l$J$$$+$H$$$&$N$,<q;]$G$9!%(B
$B!V$=$&$O8+$($J$$!W$H$$$&$N$G$"$l$P!$$=$l$O;d$NNOITB-$H$$$&$3$H$G$9!%(B

$B$3$l$O0UM_E*$G$h$$$H;W$$$^$9$,!“$b$&>/$76qBNE*$K$J$k$H$J$$h$$$G$9!#%9(B
$B%l%C%I%W%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0U$9$kI,MW$,$“$k$N$G$9(B?
$B$b$A$m$s;~4V<+BN$O(B thread
$B$K8D!9$K;}$?$;$F$*$$$FLdBj$”$j$^$;$s$7!$(B
$B85!9!$(BThreadGroup
$B<+BN$,;~4V>pJs$rJ];}$9$k$J$I$H$O8@$C$F$$$^$;$s!%(B
thread $B<+BN$OB>$N(B thread $B$H$NHf3S$J$s$FCN$i$J$$$G$7$g$&$+$i!$(B
$B%9%1%8%e!<%j%s%0$r4IM}$9$k(B thread
$B$,$=$N>pJs$rMQ$$$FH=CG$9$k$@$1$G$9!%(B

$BM%@hH=CG$^$G(B thread

$B<+?H$K$d$i$;$k$3$H$bIT2DG=$G$O$J$$$G$7$g$&$1$l$I!$(B

$B$=$l$O$$$/$i$J$s$G$b8D!9$N(B thread

$B$NC4EvHO0O$H$7$FBg$-$9$.$^$9$h$M!%(B

$B$G!$$=$N4IM}(B thread $B$,$I$N$h$&$K=hM}H=CG$9$k$+$J$N$G$9$,!$(B
thread
$B72$rG[Ns$G;}$A!$$=$l$r%9%-%c%s$7$F7h$a$k$H$$$&J}K!$b2DG=$G$7$g$&!%(B
$B$=$N>l9g!$%9%-%c%s$9$k%?%$%_%s%0$r$I$&$9$k$+$H$$$&E@$G!$(B
thread queue $B$N$h$&$J$b$N$,$J$$$H0lDj<~4|$G%A%'%C%/$K$$$/=hM}$K(B
$B$J$j$=$&$K;W$$$^(B $B!D(B $B$7$?$,!$M=4|$;$L%(%i!<=*N;$r9M$($J$$$J$i(B
$B=hM}(B thread $B$+$i4F;k(B thread $B$r(B run
$B$9$k$h$&$JJ}K!$G2DG=$G$9$M!%(B

$B=hM}(B thread $B$,<gF38"$r0.$C$F$$$k$N$,5$$KF~$j$^$;$s$,!%(B

$B4F;k(B thread $BB&$,!$=hM}(B thead
$B$N<B9T40N;$NETEY!$$=$l$KBP=h$G$-$l$P!$(B
$B%9%1%8%e!<%j%s%04IM}$b4J7i$K$J$k$N$G$O$J$$$+$H9M$($F$$$^$7$?!%(B

$B%?%9%/$4$H$KFs=E(B thread ($B<B9T(B + $B4F;k(B)
$B$H$J$k%3%9%H$r5$$K$7$J$$$N$J$i(B
(sub-thread
$B@8@.$b$9$Y$F4F;k$KI,MW$J=hCV$,;$5$l$F$$$k$H$$$&A0Ds$G(B)$B!$(B
thread queue $B$H$7$F;H$&(B queue
$B$r<+J,$G:n$k$3$H$OIT2DG=$G$O$“$j$^$;$s!%(B
$B$=$l$G==J,$@$H$$$&$N$G$”$l$P!$(BThreadGroup $B$N(B thread_queue
$B$J$I$O(B
$BL5$/$F$bNI$$$H$$$&$3$H$K$J$k$N$G$7$g$&!%(B

$B;d<+?H$OL5BL$J(B thread $B$rI,MW$H$9$k$N$O4r$7$/$J$$$7!$(Bthread queue
$B$N(B
$BOHAH$,MQ0U$5$l$F$$$l$P3Z$K$J$k$N$G4r$7$$$H9M$($F$$$^$9!%(B

$B$?$H$($P;w$?$h$&$JLdBj0U<1$H$7$F(Bclassbox$B$H$+8F$P$l$k$b$N$,$“$C$F!”$9$G$K(B
trunk$B$K$O(BModule#mix$B$H$$$&5!G=$,F~$C$F$$$k$o$1$G$9$,!“$4B8CN$G$7$?$+(B?
$B%a(B
$B%=%C%I$N2D;k@-$NJQ99$r(BModule$B$G<B8=$9$k$H$$$&$N$O$-$o$a$F<+A3$JH/A[$G$9!#(B
Module$B$O$=$N$?$a$N$b$N$G$9$+$i$M!#$7$+$k$K!”(BModule#mix$B$G$O$J$/!“(B
ThreadGroup$B$K5!G=$rDI2C$9$k!”$J$<$G$9$+!#$J$<(BModule$B$G$O$J$$$N$G$9$+!#(B

$B<B9TC10L$G$"$k(B thread $B$r8GM-4D6-$NC10L$H$7$F9M$($F$$$k$+$i$G$9!%(B
$BNI$$@bL@$,=P$F$3$J$/$FG:$s$G$$$k$N$G$9$,!$(B
Module $B$X$NAuHw$,8@8l4D6-$N%l%Y%k$GH"Dm$rMQ0U$9$k$N$KBP$7!$(B
ThreadGroup $B$X$NAuHw$O<B9T4D6-$N%l%Y%k$GH"Dm$rMQ0U$9$k$H$G$b(B
$B8@$($P$$$$$N$G$7$g$&$+!%(B

Module#mix $B$K$D$$$F$O$-$A$s$HM}2r$G$-$F$$$k$H$O8@$($J$$$N$G!$(B
$B$=$N5!G=8B3&$K$D$$$F$b$o$+$j$^$;$s!%(B
$B$?$@!$$3$3$G9M$($F$$$k(B ThreadGroup
$B$N8GM-4D6-$H$O>/$7BP>]NN0h$,0c$$!$(B
$BJBN)$G$-$kB8:_$G$"$k$h$&$K;W$$$^$9!%(B

$B$$$$$(IT<+A3$G$9!#$J$<(BThreadGroup$B$K$=$N$h$&$J5!G=$,I,MW$G$9$+(B?
safe level $B$O(B thread $B$d(B block
$B$N$h$&$J<B9T4D6-4s$j$K@_Dj$5$l$k$b$N$G$9(B
$B$N$G!$F0E*$KJQ992DG=$JOHAH$G$J$1$l$P$I$3$+$GL5M}$,=P$k$h$&$K;W$$$^$9!%(B
$B$b$A$m$s(B Module $B$K$$$$F(B binding $B$h$kJQ99$O2DG=$G$9$,!$(B
$B<B9T4D6-$H$7$F$N(B binding
$B$N40A40\9T$r9T$&$N$OL5M}LpM}46$,I:$$$^$9!%(B
$BNc$($P<B9TCf$N(B thread $B$,<+?H$NEZBf$?$k(B binding
$B$rJQ992DG=$K$9$k$N$O(B
$B8@8l;EMM$H$7$FL5Cc$G$"$k$h$&$K;W$$$^$9!%(B
$B$=$&$G$J$1$l$P(B module_eval $B$d(B binding $B$r;XDj$7$F$N(B eval
$B$J$I$K$h$k$+!$(B
$B?7$?$J(B binding $B$G(B thread
$B$r@8@.$7$F<+J,$O;`$L$+$N$h$&$J$3$H$K$J$k$N$G(B
$B$O$J$$$G$7$g$&$+!%(B
$BA0<T$O0l;~E
$JJQ99$K$7$+$J$j$^$;$s$+$i!$85$N<B9T4D6-$KLa$C$F$7$^$$$^$9!%(B
$B8e<T$O?7$?$K<B9T$7D>$7$F$$$k$o$1$G$9$+$i!$!V0\9T!W$H$O0c$$$=$&$G$9!%(B

$B8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@)8f$,(B

$BI,MW$K$J$k$N$G!"(BGVL$B$,B8:_$7$J$$(BJRuby$B$"$?$j$N%Q%U%)!<%^%s%9$K1F6A$rM?$($k$N$G$O(B

$B$J$$$+$H$$$&7|G0$,$"$j$^$9!#[9M+$@$H$$$$$N$G$9$,!#(B

$B$3$l$K$D$$$F$O$J$s$H$b!%(B
$B%a%=%C%I6u4V$K$D$$$F$OEPO?$N:]$N$_$K(B lock $B$9$l$P$$$$$N$G$O$J$$$+$H(B
$B;W$C$F$$$^$9$,!$0c$$$^$9$+$M!)(B
$B$@$H$7$?$i!$$=$3$^$GBgNL$K%a%=%C%IEPO?=hM}$r7+$jJV$9$H$$$&$N$O(B
$B$"$^$j9M$($J$/$F$b$h$5$=$&$J$N$G!$1F6A$O>.$5$$$h$&$K46$8$^$9!%(B

$BEPO?$N:]$N$_$K(B lock
$B$9$k$@$1$J$i%Q%U%)!<%^%s%9E*$K$OLdBj$J$$$H$$$&(B
$BE@$K$OF10U$7$^$9!#(B
$B$^$?!"$"$l$+$i9M$(D>$7$^$7$F!"(BGVL$B$,$J$$%b%G%k$@$H$I$&$;IaDL$N(B
define_method vs
$B%a%=%C%I%3!<%k$H$+$G$b(Block$B$,I,MW$J$N$G!“DI2C%m%C%/$O(B
$B$$$i$J$$$h$&$J5$$,$7$F$-$^$7$?!#$h$C$F!”$3$N7o$O<h$j2<$2$5$;$F$/$@$5$$!#(B

$B$J$/$O$J$$$G$9$,!$$^$@[0$m$2$J%W%i%s$G$9!%(B
$B$J$k$[$I!#(B

$B1J0f!wCNG=!%6e9)Bg$G$9!%(B

From: Yukihiro M. [email protected]
Subject: [ruby-dev:43994] Re: ThreadGroup#make_local_space!
Date: Thu, 30 Jun 2011 08:11:45 +0900
Message-ID: [email protected]

|$B4X?tE*%a%=%C%I$b;H$C$F$$$k$h$&$JIaDL$N(B Ruby $B%9%/%j%W%H$r(B
|$B4D6-1x@w$9$k$3$H$J$/$=$N$^$^F0$+$;$k4D6-$,M_$7$$$H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,!$0l;~(B
$BE*JQ99$d0\9T$OFq$7$/$J$j$=$&$G$9$,!$@5$7$$$3$H$J$N$+$b$7$l$^$;$s!%(B

$B8=:_!$$I$N(B Namespace $B$G<B9T$7$F$$$k$+$rJ];}$9$k$K$O!$B?J,!$(BVM
$B$NJ];}>p(B
$BJs$KN)$AF~$k$+!$(Bthread
$B$K;}$?$;$k$+$K$J$k$N$G$O$J$$$+$H;W$$$^$9$,!$4V(B
$B0c$C$F$$$^$9$+!)(B
VM $B$K$^$G$ON)$AF~$i$J$$HO0O$G9M$($k$H!$(BThreadGroup
$B$K>pJs$r;}$?$;$F$*(B
$B$/$N$,:G$b(B Namespace $B8!:w%3%9%H$,$+$+$i$J$$$h$&$K;W$$$^$9!%(B
$B$G!$(BThreadGroup $B$K(B Namespace
$B>pJs$r$b$?$;$k$J$i!$(Bmake_local_space! $B$G(B
$B$N$h$&$KD>@(B ThreadGroup
$B$K>pJs$r;}$?$;$k$N$HF1$8$3$H$H9M$($^$9!%(B

VM $B$,J];}$9$k<B9T4D6-$K(B Namespace
$B>pJs$rJ];}$9$k$N$G$"$l$P!$OC$OJL$G$9!%(B

|$B$3$l$i$NLdBj$N$9$Y$F$r(B safe level $B$N3HD%$GBP=h$G$-$k$H$O;W$($^$;$s!%(B
|$B2>$K(B safe level $B$+$i$N%"%W%m!<%A$G2r7h$r?^$k$H$7$F$b!$(B
|ThreadGroup $B$,4IM}C10L$H$J$C$F(B make_local_space! $B$N$h$&$J$b$N$,(B
|$BI,MW$K$J$k$@$m$&$HM=A[$7$^$9!%(B

$B$=$NE@$OH]Dj$7$^$;$s$,!“(Bmake_local_space$B$,K>$^$7$$2r$+$H$$$&(B
$B$H<+?.$,$”$j$^$;$s!#(B

$BDs0F$7$??M4V$,8@$&$N$b2?$G$9$,!$@dBP$N<+?.$,$“$C$FDs0F$7$F$$$k$o$1$G$O(B
$B$”$j$^$;$s!%(B(^_^; $BNI$$0F$N8F$S?e$K$J$k$N$G$"$l$P!$==J,$G$9!%(B

$B1J0f!wCNG=!%6e9)Bg$G$9!%(B

From: Urabe S. [email protected]
Subject: [ruby-dev:43995] Re: ThreadGroup#make_local_space!
Date: Thu, 30 Jun 2011 09:43:16 +0900
Message-ID: [email protected]

$BDs0F$J$N$G$9$,!“$?$7$+$K1J0f$5$s$NDs0F$N$[$H$s$I$NItJ,$K$O6&46$G$-$^$;$s(B
$B$,!”$$$/$D$+$N5!G=$OJL$K$“$C$F$b$$$$$H;W$&$b$N$b$”$k$N$G!"5!G=Kh$KJ,$1$F(B
$B:FDs0F$5$l$F$O$I$&$G$7$g$&$+!#(BAll or nothing$B$@$H$I$&$+$s$,$($F$b(Bnothing
$B$N$[$&$K$J$i$6$k$r$($^$;$s!#(B

All or Nothing
$B$@$H$O9M$($F$$$^$;$s$N$G!$3N$+$KL@3N$KJ,$1$?J}$,K>$^$7(B
$B$$$G$9$M!%J,$1J}$H$7$F$O!$(B

$B!&(Bthread queue
$B!&(Bmake_local_space!
$B!&$=$NB>(B

$B$H$$$&$H$3$m$G$7$g$&$+!%(B

$B$H9M$($?$b$N$,Cf?4$H$J$C$F$$$^$9(B ($B!V$D$$$G$K!W$H$$$&$b$N$,J#?t4^$^$l$F(B
$B$$$k$N$b;v<B$G$9$,(B)$B!%(B
$B$=$&$7$?<BNc!$6qBNNc$,ITB-$7$F$$$k$H$$$&HcH=$O!$(B
$B>/$J$/$H$b8=;~E@$G3N$+$K$=$N$H$*$j$G!$H]Dj$G$-$;$s!%(B

$B$@$$$?$$J,$+$C$F$-$?$N$G$9$1$l$I$b!"!V%9%l%C%I%W%m%0%i%%s%0$rJXMx$K$9(B
$B$k!W$+$i!V(BThreadGroup$B$rJXMx$K$9$k!W$N4V$KM}O@$NHtLv$,$"$k$H$$$&$U$&$K;W(B
$B$$$^$9!#$Y$D$K(BThreadGroup$B$8$c$J$/$F$b%9%l%C%I%W%m%0%i%
%s%0$,JXMx$K$J$l(B
$B$P$$$$$G$7$g$&(B?

$B!V$Y$D$K(BThreadG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&$N$G$9(B
$B$,!#$J$<$o$6$o$6(BThreadGroup$B$,=P$F$/$k$N$G$9$+(B?

$B$“!$$4$a$s$J$5$$!%$o$+$j$E$i$+$C$?$G$9$M!%(B
$B$3$NItJ,$O!$!V<B9TC10L$G$”$k(B thread
$B$r8GM-4D6-$NC10L$H$7$F9M$($F$$$k$+(B
$B$i$G$9!%!W$r<u$1$F=q$$$F$$$kItJ,$G$9!%(B
thread $B$r8GM-4D6-(B ($B%m!<%+%k6u4V(B)
$B$NC10L$H9M$($k$N$G$"$l$P!$C1=c$K$O8G(B
$BM-4D6-$N>pJs$r8D!9$N(B thread
$B$K;}$?$5$;$k$H$$$&$3$H$K$J$k$G$7$g$&!%$7$+(B
$B$78=<B$K$O!$?F;R$G6&DL$N8GM-4D6-$rMQ$$$k$3$H$,$[$H$s$I$G$7$g$&$+$iJL!9(B
$B$K;}$?$5$;$k$N$OL5BL$,B?$$!%(BThreadGroup
$B$K>pJs$r;}$C$F$*$$$F$b$i$($P$$(B
$B$$$N$G$O$J$$$+$H$$$&!$8GM-4D6-(B ($B%m!<%+%k6u4V(B)
$B$N>pJs$NJ];}>l=j$K$D$$$F(B
$B$NOC$G$9!%(B

$B1J0f!wCNG=!%6e9)Bg$G$9!%(B

From: KOSAKI Motohiro [email protected]
Subject: [ruby-dev:43996] Re: ThreadGroup#make_local_space!
Date: Thu, 30 Jun 2011 10:39:05 +0900
Message-ID: [email protected]

$B$G$7$+8+$l$J$$$N$G!“$3$N%Q%C%A$N%l%S%e!<$O$+$J$j%.%V%”%C%W5$L#$G$9!#KNIt$5$s$,(B

$B>$7$/8+$F$/$l$F$$$k$h$&$J$N$G!"$7$P$i$/@E4Q$5$;$F$/$@$5$$!#(B

$B7k6I$N$H$3$m!$MxMQNc$N%5%s%W%k$,ITB-$C$F$3$H$G$9$h$M!%9M$($^$9!%(B

$B$I$3$m$@$H;W$&$N$G$9$,!"7W;;%5!<%P$,J#?tB8:_$9$k>l9g$O;ve(BMPI$B0lBr$G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$5$l$k;~$G$9!%(B
$B$=$l$,!V<g!WL\E
$+$I$&$+$O$H$b$+$/!$(B
ThreadGroup $B$,>C$($l$P(B local space $B$b>C$(!$(B
local space $B$GDj5A$5$l$?%a%=%C%I$b>C$($k$3$H$K$J$j$^$9$M!%(B