種類
- インスタンスメソッド (358)
- 特異メソッド (192)
- 定数 (5)
ライブラリ
- ビルトイン (555)
キーワード
- DEBUG (11)
- DEBUG= (11)
-
MUTEX
_ FOR _ THREAD _ EXCLUSIVE (5) - [] (11)
-
abort
_ on _ exception (22) -
add
_ trace _ func (11) - alive? (11)
- backtrace (11)
-
backtrace
_ locations (22) - current (11)
- exclusive (11)
- exit (22)
- fetch (7)
- fork (11)
- group (11)
-
handle
_ interrupt (11) -
ignore
_ deadlock (3) - inspect (11)
- join (22)
- key? (11)
- keys (11)
- kill (22)
- list (11)
- main (11)
- name (9)
- name= (9)
- new (11)
- pass (11)
-
pending
_ interrupt? (22) - priority (11)
- priority= (11)
- raise (11)
-
report
_ on _ exception (16) -
report
_ on _ exception= (8) - run (11)
-
safe
_ level (7) -
set
_ trace _ func (11) - start (11)
- status (11)
- stop (11)
- stop? (11)
- terminate (11)
-
thread
_ variable? (11) -
thread
_ variable _ get (11) -
to
_ s (7) - value (11)
- wakeup (11)
検索結果
先頭5件
-
Thread
# priority -> Integer (9313.0) -
スレッドの優先度を返します。この値が大きいほど優先度が高くなります。 メインスレッドのデフォルト値は 0 です。新しく生成されたスレッドは親スレッドの priority を引き継ぎます。
...priority を引き継ぎます。
@param val スレッドの優先度を指定します。プラットフォームに依存します。
//emlist[例][ruby]{
Thread.current.priority # => 0
count1 = count2 = 0
a = Thread.new do
loop { count1 += 1 }
end
a.priority = -1
b = Thread.new d......o
loop { count2 += 1 }
end
b.priority = -2
count1 = count2 = 0 # reset
sleep 1 # => 1
count1 # => 13809431
count2 # => 11571921
//}... -
Thread
# priority=(val) (9213.0) -
スレッドの優先度を返します。この値が大きいほど優先度が高くなります。 メインスレッドのデフォルト値は 0 です。新しく生成されたスレッドは親スレッドの priority を引き継ぎます。
...priority を引き継ぎます。
@param val スレッドの優先度を指定します。プラットフォームに依存します。
//emlist[例][ruby]{
Thread.current.priority # => 0
count1 = count2 = 0
a = Thread.new do
loop { count1 += 1 }
end
a.priority = -1
b = Thread.new d......o
loop { count2 += 1 }
end
b.priority = -2
count1 = count2 = 0 # reset
sleep 1 # => 1
count1 # => 13809431
count2 # => 11571921
//}... -
Thread
# thread _ variable _ get(key) -> object | nil (9213.0) -
引数 key で指定した名前のスレッドローカル変数を返します。
...意]: Thread#[] でセットしたローカル変数(Fiber ローカル変数)と
異なり、Fiber を切り替えても同じ変数を返す事に注意してください。
例:
Thread.new {
Thread.current.thread_variable_set("foo", "bar") # スレッドローカル
Thread.current["f......oo"] = "bar" # Fiber ローカル
Fiber.new {
Fiber.yield [
Thread.current.thread_variable_get("foo"), # スレッドローカル
Thread.current["foo"], # Fiber ローカル
]
}.resume
}.join.value # => ['bar', nil]
こ......の例の "bar" は Thread#thread_variable_get により得られ
た値で、nil はThread#[] により得られた値です。
@see Thread#thread_variable_set, Thread#[]
@see https://magazine.rubyist.net/articles/0041/0041-200Special-note.html... -
Thread
. report _ on _ exception -> bool (9213.0) -
真の時は、いずれかのスレッドが例外によって終了した時に、その内容を $stderr に報告します。
...を $stderr に報告します。
デフォルトは false です。
Thread.new { 1.times { raise } }
は $stderr に以下のように出力します:
#<Thread:...> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
2: from -e:1:in `block......in <main>'
1: from -e:1:in `times'
これによってスレッドのエラーを早期に捕捉できるようになります。
いくつかのケースでは、この出力を望まないかもしれません。
出力を抑制するには複数の方法があります:
* 例外が......近い場所で rescue して、
その例外でスレッドが終了しないようにするのがより良い方法です。
* Thread#join や Thread#value でそのスレッドの終了を待つことが保証できるなら、
スレッド開始時に Thread.current.report_on_exception =......容を $stderr に報告します。
デフォルトは true です。
Thread.new { 1.times { raise } }
は $stderr に以下のように出力します:
#<Thread:...> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
2: from -e:1:in `blo......ck in <main>'
1: from -e:1:in `times'
これによってスレッドのエラーを早期に捕捉できるようになります。
いくつかのケースでは、この出力を望まないかもしれません。
出力を抑制するには複数の方法があります:
* 例外が... -
Thread
# ignore _ deadlock -> bool (9201.0) -
デッドロック検知を無視する機能のon/offを返します。
...デッドロック検知を無視する機能のon/offを返します。
デフォルト値はfalseで、デッドロックが検知されます。
@see Thread#ignore_deadlock=... -
Thread
# report _ on _ exception -> bool (9201.0) -
真の場合、そのスレッドが例外によって終了した時に、その内容を $stderr に報告します。
...err に報告します。
デフォルトはスレッド作成時の Thread.report_on_exception です。
@param newstate スレッド実行中に例外発生した場合、その内容を報告するかどうかを true か false で指定します。
//emlist[例][ruby]{
a = Thread.new{ Thread.......op; raise }
a.report_on_exception = true
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:0x......00007fc3f48c7908@(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
# thread _ variable?(key) -> bool (9201.0) -
引数 key で指定した名前のスレッドローカル変数が存在する場合に true、そ うでない場合に false を返します。
...true、そ
うでない場合に false を返します。
@param key 変数名を String か Symbol で指定します。
me = Thread.current
me.thread_variable_set(:oliver, "a")
me.thread_variable?(:oliver) # => true
me.thread_variable?(:stanley) # => false
[注意]: Thread#[]......でセットしたローカル変数(Fiber ローカル変数)が
対象ではない事に注意してください。
@see Thread#thread_variable_get, Thread#[]... -
Thread
. current -> Thread (9201.0) -
現在実行中のスレッド(カレントスレッド)を返します。
...現在実行中のスレッド(カレントスレッド)を返します。
p Thread.current #=> #<Thread:0x4022e6fc run>... -
Thread
:: MUTEX _ FOR _ THREAD _ EXCLUSIVE -> Mutex (9201.0) -
Thread.exclusive用のMutexオブジェクトです。
...
Thread.exclusive用のMutexオブジェクトです。......
Thread.exclusive用のMutexオブジェクトです。
(private constant です。)... -
Thread
. report _ on _ exception=(newstate) (9113.0) -
真の時は、いずれかのスレッドが例外によって終了した時に、その内容を $stderr に報告します。
...を $stderr に報告します。
デフォルトは false です。
Thread.new { 1.times { raise } }
は $stderr に以下のように出力します:
#<Thread:...> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
2: from -e:1:in `block......in <main>'
1: from -e:1:in `times'
これによってスレッドのエラーを早期に捕捉できるようになります。
いくつかのケースでは、この出力を望まないかもしれません。
出力を抑制するには複数の方法があります:
* 例外が......近い場所で rescue して、
その例外でスレッドが終了しないようにするのがより良い方法です。
* Thread#join や Thread#value でそのスレッドの終了を待つことが保証できるなら、
スレッド開始時に Thread.current.report_on_exception =......容を $stderr に報告します。
デフォルトは true です。
Thread.new { 1.times { raise } }
は $stderr に以下のように出力します:
#<Thread:...> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
2: from -e:1:in `blo......ck in <main>'
1: from -e:1:in `times'
これによってスレッドのエラーを早期に捕捉できるようになります。
いくつかのケースでは、この出力を望まないかもしれません。
出力を抑制するには複数の方法があります:
* 例外が... -
Thread
# backtrace _ locations(range) -> [Thread :: Backtrace :: Location] | nil (6401.0) -
スレッドの現在のバックトレースを Thread::Backtrace::Location の配 列で返します。
...ックトレースを Thread::Backtrace::Location の配
列で返します。
引数で指定した値が範囲外の場合、スレッドがすでに終了している場合は nil
を返します。
@param start 開始フレームの位置を数値で指定します。
@param length 取得す......@param range 取得したいフレームの範囲を示す Range オブジェクトを指定します。
Kernel.#caller_locations と似ていますが、本メソッドは self に限定
した情報を返します。
//emlist[例][ruby]{
thread = Thread.new { sleep 1 }
thread.run
thread.backtrac......e_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 (6301.0) -
スレッドの現在のバックトレースを Thread::Backtrace::Location の配 列で返します。
...ックトレースを Thread::Backtrace::Location の配
列で返します。
引数で指定した値が範囲外の場合、スレッドがすでに終了している場合は nil
を返します。
@param start 開始フレームの位置を数値で指定します。
@param length 取得す......@param range 取得したいフレームの範囲を示す Range オブジェクトを指定します。
Kernel.#caller_locations と似ていますが、本メソッドは self に限定
した情報を返します。
//emlist[例][ruby]{
thread = Thread.new { sleep 1 }
thread.run
thread.backtrac......e_locations # => ["/path/to/test.rb:1:in `sleep'", "/path/to/test.rb:1:in `block in <main>'"]
//}
@see Thread::Backtrace::Location...