るりまサーチ

最速Rubyリファレンスマニュアル検索!
82件ヒット [1-82件を表示] (0.015秒)
トップページ > クエリ:threads[x] > ライブラリ:ビルトイン[x]

別のキーワード

  1. etc sc_threads
  2. etc sc_thread_threads_max
  3. etc sc_xopen_realtime_threads
  4. etc cs_posix_v7_threads_cflags
  5. etc cs_posix_v7_threads_ldflags

クラス

キーワード

検索結果

Thread#value -> object (38.0)

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

...の終了を待ち結果を出力する例です。

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

threads
.each {|t| p t.value}

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

threads
.each {|t| p t.join.value}...

Thread#join -> self (32.0)

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

...

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

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

threads
.each {|t| t.join}...

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

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

...

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

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

threads
.each {|t| t.join}...

Enumerator (8.0)

each 以外のメソッドにも Enumerable の機能を提供するためのラッパークラスです。 また、外部イテレータとしても使えます。

...ます。
例えば以下のようなスレッドをまたいだ呼び出しはエラーになります。

//emlist[例][ruby]{
a = nil
Thread.new do
a = [1, 2, 3].each
a.next
end.join

p a.next
#=> t.rb:7:in `next': fiber called across threads (FiberError)
# from t.rb:7:in `<main>'
//}...

Fiber (8.0)

ノンプリエンプティブな軽量スレッド(以下ファイバーと呼ぶ)を提供します。 他の言語では coroutine あるいは semicoroutine と呼ばれることもあります。 Thread と違いユーザレベルスレッドとして実装されています。

...レッド間をまたがるファイバーの切り替えはできません。
例外 FiberError が発生します。

//emlist[例:][ruby]{
f = nil
Thread.new do
f = Fiber.new{}
end.join
f.resume
#=> t.rb:5:in `resume': fiber called across threads (FiberError)
# from t.rb:5:in `<main>'
//}...

絞り込み条件を変える

Thread::ConditionVariable (8.0)

スレッドの同期機構の一つである状態変数を実現するクラスです。

...クラスです。

以下も ConditionVariable を理解するのに参考になります。

https://ruby-doc.com/docs/ProgrammingRuby/html/tut_threads.html#UF

=== Condition Variable とは

あるスレッド A が排他領域で動いていたとします。スレッド A は現在空いてい...

ThreadGroup (8.0)

スレッドグループを表すクラスです。グループに属する Thread をまとめて 操作することができます。

...sleep 1; puts "#{Thread.current} finished" }
}

(ThreadGroup::Default.list - [Thread.current]).each {|th| th.join}

puts "all threads finished"

対象の Thread が Thread を起こす可能性がある場合
(Thread.exclusive参照)

Thread.exclusive do
(ThreadGroup:...