ライブラリ
- ビルトイン (15)
キーワード
- [] (1)
-
abort
_ on _ exception (1) - backtrace (1)
-
backtrace
_ locations (2) - fetch (1)
- key? (1)
- priority= (1)
-
report
_ on _ exception (1) - run (1)
-
safe
_ level (1) -
set
_ trace _ func (1) - stop? (1)
-
thread
_ variable _ set (1) - wakeup (1)
検索結果
先頭5件
-
Thread
# backtrace _ locations(range) -> [Thread :: Backtrace :: Location] | nil (18625.0) -
スレッドの現在のバックトレースを Thread::Backtrace::Location の配 列で返します。
...スレッドの現在のバックトレースを Thread::Backtrace::Location の配
列で返します。
引数で指定した値が範囲外の場合、スレッドがすでに終了している場合は nil
を返します。
@param start 開始フレームの位置を数値で指定します......似ていますが、本メソッドは self に限定
した情報を返します。
//emlist[例][ruby]{
thread = Thread.new { sleep 1 }
thread.run
thread.backtrace_locations # => ["/path/to/test.rb:1:in `sleep'", "/path/to/test.rb:1:in `block in <main>'"]
//}
@see Thread::Backtrace::Location... -
Thread
# backtrace _ locations(start = 0 , length = nil) -> [Thread :: Backtrace :: Location] | nil (18625.0) -
スレッドの現在のバックトレースを Thread::Backtrace::Location の配 列で返します。
...スレッドの現在のバックトレースを Thread::Backtrace::Location の配
列で返します。
引数で指定した値が範囲外の場合、スレッドがすでに終了している場合は nil
を返します。
@param start 開始フレームの位置を数値で指定します......似ていますが、本メソッドは self に限定
した情報を返します。
//emlist[例][ruby]{
thread = Thread.new { sleep 1 }
thread.run
thread.backtrace_locations # => ["/path/to/test.rb:1:in `sleep'", "/path/to/test.rb:1:in `block in <main>'"]
//}
@see Thread::Backtrace::Location... -
Thread
# safe _ level -> Integer (18343.0) -
self のセーフレベルを返します。カレントスレッドの safe_level は、$SAFE と同じです。
...ローバルになったため、このメソッドは obsolete になりました。
セーフレベルについてはspec/safelevelを参照してください。
//emlist[例][ruby]{
thr = Thread.new { $SAFE = 1; sleep }
Thread.current.safe_level # => 0
thr.safe_level # => 1
//}... -
Thread
# thread _ variable _ set(key , value) (18325.0) -
引数 key で指定した名前のスレッドローカル変数に引数 value をセットしま す。
...]: Thread#[] でセットしたローカル変数(Fiber ローカル変数)と
異なり、セットした変数は Fiber を切り替えても共通で使える事に注意してく
ださい。
//emlist[例][ruby]{
thr = Thread.new do
Thread.current.thread_variable_set(:cat, 'meow')
Thread.c......urrent.thread_variable_set("dog", 'woof')
end
thr.join # => #<Thread:0x401b3f10 dead>
thr.thread_variables # => [:dog, :cat]
//}
@see Thread#thread_variable_get, Thread#[]... -
Thread
# [](name) -> object | nil (361.0) -
name に対応したスレッドに固有のデータを取り出します。 name に対応するスレッド固有データがなければ nil を返し ます。
...emlist[例][ruby]{
[
Thread.new { Thread.current["name"] = "A" },
Thread.new { Thread.current[:name] = "B" },
Thread.new { Thread.current["name"] = "C" }
].each do |th|
th.join
puts "#{th.inspect}: #{th[:name]}"
end
# => #<Thread:0x00000002a54220 dead>: A
# => #<Thread:0x00000002a541a8 d......0000002a54130 dead>: C
//}
Thread#[] と Thread#[]= を用いたスレッド固有の変数は
Fiber を切り替えると異なる変数を返す事に注意してください。
//emlist[][ruby]{
def meth(newvalue)
begin
oldvalue = Thread.current[:name]
Thread.current[:name] = newvalu......ume
p Thread.current[:name]
# => nil if fiber-local
# => 2 if thread-local (The value 2 is leaked to outside of meth method.)
//}
Fiber を切り替えても同じ変数を返したい場合は
Thread#thread_variable_get と Thread#thread_variable_set
を使用してください。
@see Thread#fet... -
Thread
# abort _ on _ exception -> bool (325.0) -
真の場合、そのスレッドが例外によって終了した時に、インタプリタ 全体を中断させます。false の場合、あるスレッドで起こった例 外は、Thread#join などで検出されない限りそのスレッ ドだけをなにも警告を出さずに終了させます。
...。false の場合、あるスレッドで起こった例
外は、Thread#join などで検出されない限りそのスレッ
ドだけをなにも警告を出さずに終了させます。
デフォルトは偽です。c:Thread#exceptionを参照してください。
@param newstate 自身を......実行中に例外発生した場合、インタプリタ全体を終了させるかどうかを true か false で指定します。
//emlist[例][ruby]{
thread = Thread.new { sleep 1 }
thread.abort_on_exception # => false
thread.abort_on_exception = true
thread.abort_on_exception # => true
//}... -
Thread
# backtrace -> [String] | nil (325.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... -
Thread
# fetch(name , default = nil) {|name| . . . } -> object (325.0) -
name に関連づけられたスレッドに固有のデータを返します。 name に対応するスレッド固有データがない時には、引数 default が 与えられていればその値を、ブロックが与えられていれば そのブロックを評価した値を返します。
...と発生します。
//emlist[例][ruby]{
th = Thread.new { Thread.current[:name] = 'A' }
th.join
th.fetch(:name) # => "A"
th.fetch(:fetch, 'B') # => "B"
th.fetch('name') {|name| "Thread" + name} # => "A"
th.fetch('fetch') {|name| "Thread" + name} # => "Threadfetch"
//}
@see Thread#[]... -
Thread
# key?(name) -> bool (325.0) -
name に対応したスレッドに固有のデータが定義されていれば true を返します。
...name に対応したスレッドに固有のデータが定義されていれば
true を返します。
@param name 文字列か Symbol で指定します。
//emlist[例][ruby]{
me = Thread.current
me[:oliver] = "a"
me.key?(:oliver) # => true
me.key?(:stanley) # => false
//}... -
Thread
# priority=(val) (325.0) -
スレッドの優先度を返します。この値が大きいほど優先度が高くなります。 メインスレッドのデフォルト値は 0 です。新しく生成されたスレッドは親スレッドの priority を引き継ぎます。
...定します。プラットフォームに依存します。
//emlist[例][ruby]{
Thread.current.priority # => 0
count1 = count2 = 0
a = Thread.new do
loop { count1 += 1 }
end
a.priority = -1
b = Thread.new do
loop { count2 += 1 }
end
b.priority = -2
count1 = count2 = 0 # re... -
Thread
# report _ on _ exception -> bool (325.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
# run -> self (325.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
# set _ trace _ func(pr) -> Proc | nil (325.0) -
スレッドにトレース用ハンドラを設定します。
...nil を渡すとトレースを解除します。
設定したハンドラを返します。
//emlist[例][ruby]{
th = Thread.new do
class Trace
end
2.to_s
Thread.current.set_trace_func nil
3.to_s
end
th.set_trace_func lambda {|*arg| p arg }
th.join
# => ["line", "example.rb", 2, nil,......fc8de967798>, Thread]
# => ["c-return", "example.rb", 5, :current, #<Binding:0x00007fc8de9673b0>, Thread]
# => ["c-call", "example.rb", 5, :set_trace_func, #<Binding:0x00007fc8de966fc8>, Thread]
//}
@param pr トレースハンドラ(Proc オブジェクト) もしくは nil
@see Thread#add_trace_f... -
Thread
# stop? -> bool (325.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
# wakeup -> self (325.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...