34件ヒット
[1-34件を表示]
(0.016秒)
種類
- インスタンスメソッド (12)
- クラス (11)
- モジュール (11)
クラス
- ThreadsWait (12)
キーワード
- Monitor (11)
- MonitorMixin (11)
-
next
_ wait (6)
検索結果
先頭4件
-
ThreadsWait
# empty? -> bool (21113.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
# next _ wait(nonblock = nil) -> Thread (9113.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... -
Monitor (12.0)
-
スレッドの同期機構としてのモニター機能を提供するクラスです。 また同じスレッドから何度も lock できる Mutex としての機能も提供します。
...nitor'
buf = []
mon = Monitor.new
empty_cond = mon.new_cond
# consumer
Thread.start do
loop do
mon.synchronize do
empty_cond.wait_while { buf.empty? }
print buf.shift
end
end
end
# producer
while line = ARGF.gets
mon.synchronize do
buf.push(line)
empty_cond.signa... -
MonitorMixin (12.0)
-
スレッドの同期機構としてのモニター機能を提供するモジュールです。
...るかないかを通知する条件変数
# consumer
Thread.start do
loop do
buf.synchronize do # ロックする
empty_cond.wait_while { buf.empty? } # 配列が空である間はロックを開放して待つ
print buf.shift # 配列が空でなくなった後ロックを取得...