るりまサーチ

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

別のキーワード

  1. openssl t61string
  2. asn1 t61string
  3. matrix t
  4. t61string new
  5. fiddle type_size_t

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 3 ... > >>

Thread#value -> object (42277.0)

スレッド self が終了するまで待ち(Thread#join と同じ)、 そのスレッドのブロックが返した値を返します。スレッド実行中に例外が 発生した場合には、その例外を再発生させます。

...ッド self が終了するまで待ち(Thread#join と同じ)、
そのスレッドのブロックが返した値を返します。スレッド実行中に例外が
発生した場合には、その例外を再発生させます。

スレッドが Thread#kill によって終了した場合は、...
...を待ち結果を出力する例です。

thread
s = []
thread
s.push(Thread.new { n = rand(5); sleep n; n })
thread
s.push(Thread.new { n = rand(5); sleep n; n })
thread
s.push(Thread.new { n = rand(5); sleep n; n })

thread
s.each {|t| p t.value}

最後の行で、待ち合わせを...
...行っていることがわかりにくいと思うなら以下
のように書くこともできます。

thread
s.each {|t| p t.join.value}...

Thread#thread_variable_set(key, value) (36384.0)

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

... value をセットしま
す。

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

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

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

Thread#thread_variable_get(key) -> object | nil (36291.0)

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

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

例:

Thread
.new {
Thread
.current.thread_variable_set("foo", "bar") # スレッドローカル
Thread
.current["foo"...
...
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...

static int thread_keys_i(ID key, VALUE value, VALUE ary) (32500.0)

Thread#terminate -> self (30218.0)

スレッドの実行を終了させます。終了時に ensure 節が実行されます。

...ただし、スレッドは終了処理中(aborting)にはなりますが、
直ちに終了するとは限りません。すでに終了している場合は何もしません。このメソッドにより
終了したスレッドの Thread#value の返り値は不定です。
自身がメイン...
...exit(0)
により終了します。

Kernel.#exit と違い例外 SystemExit を発生しません。

t
h1 = Thread.new do
begin
sleep 10
ensure
p "this will be displayed"
end
end

sleep 0.1
t
h1.kill

#=> "this will be displayed"

@see Kernel.#exit, Kernel.#exit!...

絞り込み条件を変える

Thread.report_on_exception -> bool (27142.0)

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

...、その内容を $stderr に報告します。

デフォルトは false です。

Thread
.new { 1.times { raise } }

は $stderr に以下のように出力します:

#<Thread:...> terminated with exception (report_on_exception is true):
T
raceback (most recent call last):
2: from...
...-e:1:in `block in <main>'
1: from -e:1:in `times'

これによってスレッドのエラーを早期に捕捉できるようになります。
いくつかのケースでは、この出力を望まないかもしれません。
出力を抑制するには複数の方法があります:...
...が終了しないようにするのがより良い方法です。
* Thread#join や Thread#value でそのスレッドの終了を待つことが保証できるなら、
スレッド開始時に Thread.current.report_on_exception = false でレポートを無効化しても
安全です。...
...、その内容を $stderr に報告します。

デフォルトは true です。

Thread
.new { 1.times { raise } }

は $stderr に以下のように出力します:

#<Thread:...> terminated with exception (report_on_exception is true):
T
raceback (most recent call last):
2: from...

Thread.report_on_exception=(newstate) (27142.0)

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

...、その内容を $stderr に報告します。

デフォルトは false です。

Thread
.new { 1.times { raise } }

は $stderr に以下のように出力します:

#<Thread:...> terminated with exception (report_on_exception is true):
T
raceback (most recent call last):
2: from...
...-e:1:in `block in <main>'
1: from -e:1:in `times'

これによってスレッドのエラーを早期に捕捉できるようになります。
いくつかのケースでは、この出力を望まないかもしれません。
出力を抑制するには複数の方法があります:...
...が終了しないようにするのがより良い方法です。
* Thread#join や Thread#value でそのスレッドの終了を待つことが保証できるなら、
スレッド開始時に Thread.current.report_on_exception = false でレポートを無効化しても
安全です。...
...、その内容を $stderr に報告します。

デフォルトは true です。

Thread
.new { 1.times { raise } }

は $stderr に以下のように出力します:

#<Thread:...> terminated with exception (report_on_exception is true):
T
raceback (most recent call last):
2: from...

Thread#exit -> self (27118.0)

スレッドの実行を終了させます。終了時に ensure 節が実行されます。

...ただし、スレッドは終了処理中(aborting)にはなりますが、
直ちに終了するとは限りません。すでに終了している場合は何もしません。このメソッドにより
終了したスレッドの Thread#value の返り値は不定です。
自身がメイン...
...exit(0)
により終了します。

Kernel.#exit と違い例外 SystemExit を発生しません。

t
h1 = Thread.new do
begin
sleep 10
ensure
p "this will be displayed"
end
end

sleep 0.1
t
h1.kill

#=> "this will be displayed"

@see Kernel.#exit, Kernel.#exit!...

static VALUE thgroup_add(VALUE group, VALUE thread) (26500.0)

<< 1 2 3 ... > >>