るりまサーチ

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

別のキーワード

  1. _builtin to_r
  2. open3 pipeline_r
  3. matrix elements_to_r
  4. fileutils rm_r
  5. fileutils cp_r

ライブラリ

キーワード

検索結果

<< 1 2 3 ... > >>

Thread#priority -> Integer (9201.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) (9201.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#ignore_deadlock -> bool (9101.0)

デッドロック検知を無視する機能のon/offを返します。

...デッドロック検知を無視する機能のon/offを返します。

デフォルト値はfalseで、デッドロックが検知されます。


@see Thread#ignore_deadlock=...

Thread#ignore_deadlock=(bool) (9101.0)

デッドロック検知を無視する機能をon/offします。デフォルト値はfalseです。

...す。

trueを渡すとデッドロックを検知しなくなります。

//emlist[][ruby]{
Thread
.ignore_deadlock = true
queue = Thread::Queue.new

trap(:SIGUSR1){queue.push "Received signal"}

# ignore_deadlockがfalseだとエラーが発生する
puts queue.pop
//}

@see Thread#ignore_deadloc...

Thread#report_on_exception -> bool (9101.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#report_on_exception=(newstate) (9101.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 (9101.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#thread_variable_get(key) -> object | nil (9101.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#thread_variable_set(key, value) (9101.0)

引数 key で指定した名前のスレッドローカル変数に引数 value をセットしま す。

... Thread#[] でセットしたローカル変数(Fiber ローカル変数)と
異なり、セットした変数は Fiber を切り替えても共通で使える事に注意してく
ださい。

//emlist[例][ruby]{
thr = Thread.new do
Thread
.current.thread_variable_set(:cat, 'meow')
Thread
.cur...
...rent.thread_variable_set("dog", 'woof')
end
thr.join # => #<Thread:0x401b3f10 dead>
thr.thread_variables # => [:dog, :cat]
//}

@see Thread#thread_variable_get, Thread#[]...

Thread.current -> Thread (9101.0)

現在実行中のスレッド(カレントスレッド)を返します。

...現在実行中のスレッド(カレントスレッド)を返します。

p Thread.current #=> #<Thread:0x4022e6fc run>...

絞り込み条件を変える

Thread.report_on_exception -> bool (9101.0)

真の時は、いずれかのスレッドが例外によって終了した時に、その内容を $stderr に報告します。

...容を $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'

これによってスレッドのエラーを早期に捕捉できるようになります。
いくつかのケースでは、この出力を望まないかもしれません。
出力を抑制するには複数の方法があります:

* 例外が...
...近い場所で rescue して、
その例外でスレッドが終了しないようにするのがより良い方法です。
* Thread#join や Thread#value でそのスレッドの終了を待つことが保証できるなら、
スレッド開始時に Thread.current.report_on_exception =...
<< 1 2 3 ... > >>