別のキーワード
検索結果
-
Thread
:: ConditionVariable (6008.0) -
スレッドの同期機構の一つである状態変数を実現するクラスです。
...の一つである状態変数を実現するクラスです。
以下も ConditionVariable を理解するのに参考になります。
https://ruby-doc.com/docs/ProgrammingRuby/html/tut_threads.html#UF
=== Condition Variable とは
あるスレッド A が排他領域で動いていたとし......リソースの空きを
待っていても、いつまでも空くことはありません。
以上のような状況を解決するのが Condition Variable です。
スレッド a で条件(リソースが空いているかなど)が満たされるまで wait メソッドで
スレッドを......l = []
th = Thread.new {
for obj in foods
q.send(obj)
print "sent ", obj, "\n"
end
q.send nil
}
l.push th
th = Thread.new {
while obj = q.recv
print "recv ", obj, "\n"
end
}
l.push th
l.each do |t|
t.join...