るりまサーチ

最速Rubyリファレンスマニュアル検索!
555件ヒット [1-100件を表示] (0.172秒)
トップページ > クエリ:-[x] > クエリ:r[x] > クラス:Thread[x]

別のキーワード

  1. _builtin -
  2. open-uri open
  3. irb/input-method new
  4. irb/input-method gets
  5. matrix -

ライブラリ

キーワード

検索結果

<< 1 2 3 ... > >>

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...
<< 1 2 3 ... > >>