るりまサーチ

最速Rubyリファレンスマニュアル検索!
84件ヒット [1-84件を表示] (0.027秒)

別のキーワード

  1. drb thread
  2. etc sc_thread_threads_max
  3. thread backtrace_locations
  4. thread pending_interrupt?
  5. tracer get_thread_no

ライブラリ

クラス

キーワード

検索結果

Thread#run -> self (30099.0)

停止状態(stop)のスレッドを再開させます。 Thread#wakeup と異なりすぐにスレッドの切り替え を行います。

...ます。
Thread
#wakeup と異なりすぐにスレッドの切り替え
を行います。

@raise ThreadError 死んでいるスレッドに対して実行すると発生します。

//emlist[例][ruby]{
a = Thread.new { puts "a"; Thread.stop; puts "c" }
sleep
0.1 while a.status!='sleep'
puts "Go...
...t here"
a.run
a.join
# => a
# => Got here
# => c
//}

@see Thread#wakeup, Thread.stop...

Thread#wakeup -> self (30067.0)

停止状態(stop)のスレッドを実行可能状態(run)にします。

...を実行可能状態(run)にします。

@raise ThreadError 死んでいるスレッドに対して実行すると発生します。

//emlist[例][ruby]{
c = Thread.new { Thread.stop; puts "hey!" }
sleep
0.1 while c.status!='sleep'
c.wakeup
c.join
# => "hey!"
//}

@see Thread#run, Thread.stop...

Thread#join -> self (30061.0)

スレッド self の実行が終了するまで、カレントスレッドを停止し ます。self が例外により終了していれば、その例外がカレントス レッドに対して発生します。

...raise ThreadError join を実行することによってデッドロックが起きる場合に発生します。またカレントスレッドを join したときにも発生します。

以下は、生成したすべてのスレッドの終了を待つ例です。

thread
s = []
thread
s.pus...
...h(Thread.new { n = rand(5); sleep n; n })
thread
s.push(Thread.new { n = rand(5); sleep n; n })
thread
s.push(Thread.new { n = rand(5); sleep n; n })

thread
s.each {|t| t.join}...

Thread#join(limit) -> self | nil (30061.0)

スレッド self の実行が終了するまで、カレントスレッドを停止し ます。self が例外により終了していれば、その例外がカレントス レッドに対して発生します。

...raise ThreadError join を実行することによってデッドロックが起きる場合に発生します。またカレントスレッドを join したときにも発生します。

以下は、生成したすべてのスレッドの終了を待つ例です。

thread
s = []
thread
s.pus...
...h(Thread.new { n = rand(5); sleep n; n })
thread
s.push(Thread.new { n = rand(5); sleep n; n })
thread
s.push(Thread.new { n = rand(5); sleep n; n })

thread
s.each {|t| t.join}...

Thread::Mutex#sleep(timeout = nil) -> Integer (24144.0)

与えられた秒数の間ロックを解除してスリープして、実行後にまたロックします。

...する秒数を指定します。省略するとスリープし続けます。

@return スリープしていた秒数を返します。

@raise ThreadError 自身がカレントスレッドによってロックされていない場合に発生します。

[注意] 2.0 以降ではスリープ中...
...グナルを受信した場合などに実行が再
開(spurious wakeup)される場合がある点に注意してください。

//emlist[例][ruby]{
m = Mutex.new
th = Thread.new do
m.lock
m.sleep(2)
end
th.status # => "run"
sleep
1
th.status # => "sleep"
sleep
1
th.status # => false
//}...
...プし続けます。

@return タイムアウトした時は nil を、それ以外はスリープしていた秒数を返します。

@raise ThreadError 自身がカレントスレッドによってロックされていない場合に発生します。

[注意] 2.0 以降ではスリープ中で...

絞り込み条件を変える

Mutex#sleep(timeout = nil) -> Integer (18144.0)

与えられた秒数の間ロックを解除してスリープして、実行後にまたロックします。

...する秒数を指定します。省略するとスリープし続けます。

@return スリープしていた秒数を返します。

@raise ThreadError 自身がカレントスレッドによってロックされていない場合に発生します。

[注意] 2.0 以降ではスリープ中...
...グナルを受信した場合などに実行が再
開(spurious wakeup)される場合がある点に注意してください。

//emlist[例][ruby]{
m = Mutex.new
th = Thread.new do
m.lock
m.sleep(2)
end
th.status # => "run"
sleep
1
th.status # => "sleep"
sleep
1
th.status # => false
//}...

ThreadGroup#add(thread) -> self (6373.0)

スレッド thread が属するグループを自身に変更します。

...レッド thread が属するグループを自身に変更します。

@param thread 自身に加えたいスレッドを指定します。

@raise ThreadError 自身が freeze されているか enclose されている場合に、発生します。また引数 thread が属する ThreadGroup が...
...s #{ThreadGroup::Default.list}"
# => Initial group is [#<Thread:0x4a49168 run>]

tg = ThreadGroup.new
t1 = Thread.new { sleep }
t2 = Thread.new { sleep }
puts "t1 is #{t1}" # => t1 is #<Thread:0x50bef60>
puts "t2 is #{t2}" # => t2 is #<Thread:0x50beed0>
tg.add(t1)
puts "Initial group now #{ThreadGro...
...up::Default.list}"
# => Initial group now [#<Thread:0x3039168 run>, #<Thread:0x50beed0 run>]
puts "tg group now #{tg.list}"
# => tg group now [#<Thread:0x50bef60 run>]
//}...

ThreadGroup#enclose -> self (6095.0)

自身への ThreadGroup#add によるスレッドの追加・削除を禁止します。 enclose された ThreadGroup に追加や削除を行うと例外 ThreadError が発生します。

...自身への ThreadGroup#add によるスレッドの追加・削除を禁止します。
enclose された ThreadGroup に追加や削除を行うと例外 ThreadError が発生します。

ただし、Thread.new によるスレッドの追加は禁止されません。enclose されたスレッ...
...に属します。

追加の例:

thg = ThreadGroup.new.enclose
thg.add Thread.new {}

=> -:2:in `add': can't move to the enclosed thread group (ThreadError)

削除の例:

thg1 = ThreadGroup.new
thg2 = ThreadGroup.new

th = Thread.new {sleep 1}

thg1.add th
thg1.enclose
thg2.ad...
...d th

=> -:8:in `add': can't move from the enclosed thread group (ThreadError)...