るりまサーチ

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

別のキーワード

  1. _builtin enq
  2. queue enq
  3. sizedqueue enq
  4. thread enq

ライブラリ

検索結果

Thread::ConditionVariable (13.0)

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

...います。

require 'thread'

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

def count
@q.size
end

def enq(v)
@mutex.synchronize{...
...@empty.wait(@mutex) if count == 0
v = @q.shift
@full.signal if count == (@max - 1)
v
}
end

alias send enq
alias recv deq
end

if __FILE__ == $0
q = TinyQueue.new(1)
foods = 'Apple Banana Strawberry Udon Rice Milk'.split
l = []

t...