るりまサーチ

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

別のキーワード

  1. openssl new
  2. _builtin new
  3. rexml/document new
  4. resolv new
  5. socket new

ライブラリ

キーワード

検索結果

Thread::ConditionVariable (55.0)

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

...レッド a に対して条件が成立したことを通知します。これが典型的な
使用例です。

mutex = Mutex.new
cv = ConditionVariable.new

a = Thread.start {
mutex.synchronize {
...
while (条件が満たされない)
cv.wait(m...
...tion Variable を使って wait しています。

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 e...
...t == 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 = []

th = Thread.new {
for obj in f...

Monitor (31.0)

スレッドの同期機構としてのモニター機能を提供するクラスです。 また同じスレッドから何度も lock できる Mutex としての機能も提供します。

...生産者問題の例][ruby]{
require 'monitor'

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 d...
...にならない例][ruby]{
require 'monitor'
mon = Monitor.new
mon.synchronize {
mon.synchronize {
}
}
//}

Thread::Mutex ではデッドロックになります。

//emlist[Mutex でデッドロックになる例][ruby]{
mx = Mutex.new
mx.synchronize {
mx.synchronize {
}
}
# => deadlock; r...