るりまサーチ

最速Rubyリファレンスマニュアル検索!
12件ヒット [1-12件を表示] (0.003秒)

キーワード

検索結果

ConditionVariable (3.0)

Alias of Thread::ConditionVariable

...Alias of Thread::ConditionVariable...

Queue (3.0)

Alias of Thread::Queue

...Alias of Thread::Queue...

SizedQueue (3.0)

Alias of Thread::SizedQueue

...Alias of Thread::SizedQueue...

Thread::ConditionVariable (3.0)

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

...クラスです。

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

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

=== Condition Variable とは

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

a = Thread.start {
mutex.synchronize {
...
while (条件が満たされない)
cv.wait(mutex)
end
...
}
}

b = Thread.start {
mutex.synchronize {
# 上の...
...@q が空になった場合、
あるいは満タンになった場合に Condition Variable を使って wait しています。

require 'thread'

class
TinyQueue
def initialize(max=2)
@max = max
@full = ConditionVariable.new
@empty = ConditionVariable.new
@mutex =...

Thread::Queue (3.0)

Queue はスレッド間の FIFO(first in first out) の通信路です。ス レッドが空のキューを読み出そうとすると停止します。キューになんら かの情報が書き込まれると実行は再開されます。

...と実行は再開されます。

最大サイズが指定できる Queue のサブクラス Thread::SizedQueue も提供されています。

=== 例

require 'thread'

q = Queue.new

th1 = Thread.start do
while resource = q.pop
puts resource
end
end

[:resource1, :resourc...

絞り込み条件を変える

Thread::SizedQueue (3.0)

サイズの最大値を指定できる Thread::Queue です。

... Thread::Queue です。

=== 例

283 より。q をサイズ 1 の SizedQueue オブジェクトに
することによって、入力される行と出力される行が同じ順序になります。
q = [] にすると入力と違った順序で行が出力されます。

require 'thread'...
...q = SizedQueue.new(1)

th = Thread.start {
while line = q.pop
print line
end
}

while l = gets
q.push(l)
end
q.push(l)

th.join...