別のキーワード
種類
- インスタンスメソッド (42)
- クラス (24)
- 特異メソッド (18)
- 文書 (12)
クラス
- ThreadsWait (60)
キーワード
- ConditionVariable (12)
- Fiber (12)
-
all
_ waits (18) - empty? (6)
- finished? (6)
- join (6)
-
join
_ nowait (6) - new (6)
-
next
_ wait (6) -
ruby 1
. 8 . 4 feature (12)
検索結果
先頭5件
-
ThreadsWait
# threads -> Array (21131.0) -
同期されるスレッドの一覧を配列で返します。
...されるスレッドの一覧を配列で返します。
使用例
require 'thwait'
threads = []
3.times {|i|
threads << Thread.new { sleep 1; p Thread.current }
}
thall = ThreadsWait.new(*threads)
p thall.threads
#=> [#<Thread:0x21750 sleep>, #<Thread:0x216c4 sleep>, #<Thread:... -
ThreadsWait
. new(*threads) -> ThreadsWait (3231.0) -
指定されたスレッドの終了をまつための、スレッド同期オブジェクトをつくります。
...をつくります。
@param threads 終了を待つスレッドを一つもしくは複数指定します。
使用例
require 'thwait'
threads = []
5.times {|i|
threads << Thread.new { sleep 1; p Thread.current }
}
thall = ThreadsWait.new(*threads)
thall.all_waits{|th|
pr... -
ThreadsWait
# join(*threads) -> () (3165.0) -
終了を待つスレッドの対象として、threads で指定されたスレッドを指定します。
...threads で指定されたスレッドを指定します。
@param threads 複数スレッドの終了を待つスレッドに指定されたthreadsを加えます。
require 'thwait'
threads = []
5.times {|i|
threads << Thread.new { sleep 1; p Thread.current }
}
thall = ThreadsWai......t.new
p thall.threads #=> []
thall.join(*threads)
p thall.threads
#=> [#<Thread:0x216ec dead>, #<Thread:0x21660 dead>, #<Thread:0x215d4 dead>, #<Thread:0x214bc dead>]... -
ThreadsWait
# join _ nowait(*threads) -> () (3165.0) -
終了を待つスレッドの対象として、threads で指定されたスレッドを指定します。 しかし、実際には終了をまちません。
...して、threads で指定されたスレッドを指定します。
しかし、実際には終了をまちません。
@param threads 複数スレッドの終了を待つスレッドに指定されたthreadsを加えます。
require 'thwait'
threads = []
5.times {|i|
threads << Threa......d.new { sleep 1; p Thread.current }
}
thall = ThreadsWait.new
p thall.threads #=> []
thall.join_nowait(*threads)
p thall.threads #=> [#<Thread:0x21638 sleep>, #<Thread:0x215ac sleep>, #<Thread:0x21520 sleep>, #<Thread:0x21494 sleep>, #<Thread:0x21408 sleep>]
# 実際には終了を待... -
ThreadsWait
. all _ waits(*threads) -> () (3132.0) -
指定されたスレッドすべてが終了するまで待ちます。 ブロックが与えられた場合、スレッド終了時にブロックを評価します。
...クを評価します。
@param threads 終了するまでまつスレッドを一つもしくは複数指定します。
require 'thwait'
threads = []
5.times {|i|
threads << Thread.new { sleep 1; p Thread.current }
}
ThreadsWait.all_waits(*threads) {|th| printf("end %s\n", th.insp... -
ThreadsWait
. all _ waits(*threads) {|thread| . . . } -> () (3132.0) -
指定されたスレッドすべてが終了するまで待ちます。 ブロックが与えられた場合、スレッド終了時にブロックを評価します。
...クを評価します。
@param threads 終了するまでまつスレッドを一つもしくは複数指定します。
require 'thwait'
threads = []
5.times {|i|
threads << Thread.new { sleep 1; p Thread.current }
}
ThreadsWait.all_waits(*threads) {|th| printf("end %s\n", th.insp... -
ThreadsWait
# empty? -> bool (3036.0) -
同期されるスレッドが存在するならば true をかえします。
...ッドが存在するならば true をかえします。
使用例
require 'thwait'
threads = []
3.times {|i|
threads << Thread.new { sleep 1; p Thread.current }
}
thall = ThreadsWait.new
p thall.threads.empty? #=> true
thall.join(*threads)
p thall.threads.empty? #=> false... -
ThreadsWait
# all _ waits -> () (3024.0) -
指定されたスレッドすべてが終了するまで待ちます。 ブロックが与えられた場合、スレッド終了時にブロックを評価します。
...合、スレッド終了時にブロックを評価します。
使用例
require 'thwait'
threads = []
5.times {|i|
threads << Thread.new { sleep 1; p Thread.current }
}
thall = ThreadsWait.new(*threads)
thall.all_waits{|th|
printf("end %s\n", th.inspect)
}
# 出力... -
ThreadsWait
# finished? -> bool (3024.0) -
すでに終了したスレッドが存在すれば true を返します。
...に終了したスレッドが存在すれば true を返します。
使用例
require 'thwait'
threads = []
3.times {|i|
threads << Thread.new { sleep 1; p Thread.current }
}
thall = ThreadsWait.new(*threads)
p thall.finished? #=> false
sleep 3
p thall.finished? #=> true... -
ThreadsWait
# next _ wait(nonblock = nil) -> Thread (3024.0) -
指定したスレッドのどれかが終了するまで待ちます。
... ThreadsWait::ErrNoFinishedThread が発生します。
@raise ErrNoWaitingThread 終了をまつスレッドが存在しない時、発生します。
@raise ErrNoFinishedThread nonblock がtrue でかつ、キューが空の時、発生します。
#使用例
require 'thwait'
threads = [......]
2.times {|i|
threads << Thread.new { sleep i }
}
thall = ThreadsWait.new
thall.join_nowait(*threads)
until thall.empty?
th = thall.next_wait
p th
end
@see Queue#pop... -
ruby 1
. 8 . 4 feature (18.0) -
ruby 1.8.4 feature ruby 1.8.4 での ruby 1.8.3 からの変更点です。
...追加されました.
#Wed Dec 7 01:02:04 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
#
# * ext/tk/tcltklib.c: fix bug on switching threads and waiting on the
# deleted interpreter on vwait and tkwait command.
削除された Tk インタープリタに対して vwait や......) の IP
オブジェクトがデフォルトの IP オブジェクト (デフォルトのスレッドグルー
プに属するもの.require 'multi-tk' の際に生成される) であるか,操作し
ようとしている IP オブジェクトが自らの直接の slave IP であ......DEで無効なマルチバイト文字列や、改行を含む文字列を引数に渡
すと切り捨てられていたバグの修正。
require "optparse"
puts "[#{ARGV * ', '}]"
ARGV.options do |opt|
opt.on("-n NODE") {|v| puts v }
opt.parse!... -
Fiber (12.0)
-
ノンプリエンプティブな軽量スレッド(以下ファイバーと呼ぶ)を提供します。 他の言語では coroutine あるいは semicoroutine と呼ばれることもあります。 Thread と違いユーザレベルスレッドとして実装されています。
...ます。
ファイバーが終了するとその親にコンテキストが切り替わります。
なお標準添付ライブラリ fiber を require することにより、
コンテキストの切り替えに制限のない Fiber#transfer が使えるようになります。
任意のファ......レッド間をまたがるファイバーの切り替えはできません。
例外 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>'
//}......点で解消されます。
ファイバーが終了するとその親にコンテキストが切り替わります。
Ruby 3.1 から fiber を require しなくても、
コンテキストの切り替えに制限のない Fiber#transfer が使えます。
任意のファイバーにコンテキ... -
Thread
:: ConditionVariable (12.0) -
スレッドの同期機構の一つである状態変数を実現するクラスです。
...クラスです。
以下も ConditionVariable を理解するのに参考になります。
https://ruby-doc.com/docs/ProgrammingRuby/html/tut_threads.html#UF
=== Condition Variable とは
あるスレッド A が排他領域で動いていたとします。スレッド A は現在空いてい......る例です。@q が空になった場合、
あるいは満タンになった場合に Condition Variable を使って wait しています。
require 'thread'
class TinyQueue
def initialize(max=2)
@max = max
@full = ConditionVariable.new
@empty = ConditionVariable.new...