るりまサーチ (Ruby 2.6.0)

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

別のキーワード

  1. _builtin new
  2. _builtin inspect
  3. _builtin to_s
  4. _builtin each

ライブラリ

キーワード

検索結果

Thread#[](name) -> object | nil (78304.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#[]=(name,val) (42304.0)

val を name に対応するスレッド固有のデータとして格納します。

...ーを文字列か Symbol で指定します。文字列を指定した場合は String#to_sym によりシンボルに変換されます。

@param val スレッド固有データを指定します。nil を指定するとそのスレッド固有データは削除されます。


@see Thread#[]...

Thread#join -> self (24022.0)

スレッド self の実行が終了するまで、カレントスレッドを停止し ます。self が例外により終了していれば、その例外がカレントス レッドに対して発生します。

...raise ThreadError join を実行することによってデッドロックが起きる場合に発生します。またカレントスレッドを join したときにも発生します。

以下は、生成したすべてのスレッドの終了を待つ例です。

thread
s = []
thread
s.pus...
...h(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| t.join}...

Thread#join(limit) -> self | nil (24022.0)

スレッド self の実行が終了するまで、カレントスレッドを停止し ます。self が例外により終了していれば、その例外がカレントス レッドに対して発生します。

...raise ThreadError join を実行することによってデッドロックが起きる場合に発生します。またカレントスレッドを join したときにも発生します。

以下は、生成したすべてのスレッドの終了を待つ例です。

thread
s = []
thread
s.pus...
...h(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| t.join}...

Thread#value -> object (24022.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}...

絞り込み条件を変える