種類
- インスタンスメソッド (8)
- 特異メソッド (2)
ライブラリ
- ビルトイン (10)
キーワード
- alive? (1)
- backtrace (1)
-
handle
_ interrupt (1) -
report
_ on _ exception (1) -
report
_ on _ exception= (1) - run (1)
- status (1)
- stop? (1)
- wakeup (1)
検索結果
先頭5件
-
Thread
. stop -> nil (81445.0) -
他のスレッドから Thread#run メソッドで再起動されるまで、カレ ントスレッドの実行を停止します。
...ドから Thread#run メソッドで再起動されるまで、カレ
ントスレッドの実行を停止します。
//emlist[例][ruby]{
a = Thread.new { print "a"; Thread.stop; print "c" }
sleep 0.1 while a.status!='sleep'
print "b"
a.run
a.join
# => "abc"
//}
@see Thread#run, Thread#wakeup... -
Thread
# stop? -> bool (45499.0) -
スレッドが終了(dead)あるいは停止(stop)している時、true を返します。
...スレッドが終了(dead)あるいは停止(stop)している時、true を返します。
//emlist[例][ruby]{
a = Thread.new { Thread.stop }
b = Thread.current
a.stop? # => true
b.stop? # => false
//}
@see Thread#alive?, Thread#status... -
Thread
. handle _ interrupt(hash) { . . . } -> object (27292.0) -
スレッドの割り込みのタイミングを引数で指定した内容に変更してブロックを 実行します。
...ングを引数で指定した内容に変更してブロックを
実行します。
「割り込み」とは、非同期イベントや Thread#raise や
Thread#kill、Signal.#trap(未サポート)、メインスレッドの終了
(メインスレッドが終了すると、他のスレッドも終......してください。
=== 使い方
例:Thread#raise 発生のタイミングを制御する例
th = Thread.new do
Thread.handle_interrupt(RuntimeError => :never) {
begin
# 安全にリソースの割り当てが可能
Thread.handle_interrupt(RuntimeError => :immediate......) {
# ...
}
ensure
# 安全にリソースの解放が可能
end
}
end
Thread.pass
# ...
th.raise "stop"
RuntimeError を無視(延期)している間はリソースの割り当てや ensure
節でリソースの解放を安全に行う事ができ... -
Thread
# status -> String | false | nil (27238.0) -
生きているスレッドの状態を文字列 "run"、"sleep", "aborting" のいず れかで返します。正常終了したスレッドに対して false、例外によ り終了したスレッドに対して nil を返します。
...て nil を返します。
Thread#alive? が真を返すなら、このメソッドも真です。
例:
a = Thread.new { raise("die now") }
b = Thread.new { Thread.stop }
c = Thread.new { Thread.exit }
d = Thread.new { sleep }
d.kill #=> #<Thread:0x401b3678 aborting>
a.......status #=> nil
b.status #=> "sleep"
c.status #=> false
d.status #=> "aborting"
Thread.current.status #=> "run"
@see Thread#alive?, Thread#stop?... -
Thread
# run -> self (27208.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 "Got here"
a.run
a.join
# => a
# => Got here
# => c
//}
@see Thread#wakeup, Thread.stop... -
Thread
# report _ on _ exception -> bool (27202.0) -
真の場合、そのスレッドが例外によって終了した時に、その内容を $stderr に報告します。
...ルトはスレッド作成時の Thread.report_on_exception です。
@param newstate スレッド実行中に例外発生した場合、その内容を報告するかどうかを true か false で指定します。
//emlist[例][ruby]{
a = Thread.new{ Thread.stop; raise }
a.report_on_exception......true
a.run
# => #<Thread:0x00007fc3f48c7908@(irb):1 run> terminated with exception (report_on_exception is true):
# Traceback (most recent call last):
# (irb):1:in `block in irb_binding': unhandled exception
# #<Thread:0x00007fc3f48c7908@(irb):1 dead>
b = Thread.new{ Thread.stop; raise }
b.......report_on_exception = false
b.run # => #<Thread:0x00007fc3f48aefc0@(irb):4 dead>
//}
@see Thread.report_on_exception... -
Thread
# report _ on _ exception=(newstate) (27202.0) -
真の場合、そのスレッドが例外によって終了した時に、その内容を $stderr に報告します。
...ルトはスレッド作成時の Thread.report_on_exception です。
@param newstate スレッド実行中に例外発生した場合、その内容を報告するかどうかを true か false で指定します。
//emlist[例][ruby]{
a = Thread.new{ Thread.stop; raise }
a.report_on_exception......true
a.run
# => #<Thread:0x00007fc3f48c7908@(irb):1 run> terminated with exception (report_on_exception is true):
# Traceback (most recent call last):
# (irb):1:in `block in irb_binding': unhandled exception
# #<Thread:0x00007fc3f48c7908@(irb):1 dead>
b = Thread.new{ Thread.stop; raise }
b.......report_on_exception = false
b.run # => #<Thread:0x00007fc3f48aefc0@(irb):4 dead>
//}
@see Thread.report_on_exception... -
Thread
# wakeup -> self (27160.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
# alive? -> bool (27130.0) -
スレッドが「生きている」時、true を返します。
...」時、true を返します。
例:
thr = Thread.new { }
thr.join # => #<Thread:0x401b3fb0 dead>
Thread.current.alive? # => true
thr.alive? # => false
Thread#status が真を返すなら、このメソッドも真です。
@see Thread#status, Thread#stop?... -
Thread
# backtrace -> [String] | nil (27058.0) -
スレッドの現在のバックトレースを返します。
...している場合は nil を返します。
//emlist[例][ruby]{
class C1
def m1
sleep 5
end
def m2
m1
end
end
th = Thread.new {C1.new.m2; Thread.stop}
th.backtrace
# => [
# [0] "(irb):3:in `sleep'",
# [1] "(irb):3:in `m1'",
# [2] "(irb):6:in `m2'",
# [3] "(irb...