るりまサーチ

最速Rubyリファレンスマニュアル検索!
11件ヒット [1-11件を表示] (0.104秒)
トップページ > クエリ:I[x] > クエリ:h[x] > クエリ:EMPTY[x] > クエリ:deq[x] > 種類:クラス[x]

別のキーワード

  1. _builtin to_h
  2. env to_h
  3. hash to_h
  4. array to_h
  5. ostruct to_h

ライブラリ

検索結果

Thread::ConditionVariable (9031.0)

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

...一つである状態変数を実現するクラスです。

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

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

=== Condition Variable とは

あるスレッド A が排他領域で動いていたとしま...
...
cv.signal
}
}

以下は 14445 で紹介されている例です。@q が空になった場合、
あるいは満タンになった場合に Condition Variable を使って wait しています。

require 'thread'

class
TinyQueue
def initialize(max=2)
@max =...
...@full = ConditionVariable.new
@empty = ConditionVariable.new
@mutex = Mutex.new
@q = []
end

def count
@q.size
end

def enq(v)
@mutex.synchronize{
@full.wait(@mutex) if count == @max
@q.push v
@empty.signal if count == 1...