38件ヒット
[1-38件を表示]
(0.061秒)
種類
- インスタンスメソッド (29)
- クラス (9)
クラス
- Mutex (2)
-
Thread
:: ConditionVariable (18) -
Thread
:: Mutex (9)
キーワード
- ConditionVariable (9)
- broadcast (9)
- signal (9)
検索結果
先頭5件
-
Mutex
# synchronize { . . . } -> object (26115.0) -
mutex をロックし、ブロックを実行します。実行後に必ず mutex のロックを解放します。
...また、Signal.#trap に指定したハンドラ内で実行
した場合に発生します。
//emlist[例][ruby]{
m = Mutex.new
result = m.synchronize do
m.locked? # => true
# critical part
"result"
end
m.locked? # => false
result # => "result"
//}... -
Thread
:: Mutex # synchronize { . . . } -> object (26115.0) -
mutex をロックし、ブロックを実行します。実行後に必ず mutex のロックを解放します。
...また、Signal.#trap に指定したハンドラ内で実行
した場合に発生します。
//emlist[例][ruby]{
m = Mutex.new
result = m.synchronize do
m.locked? # => true
# critical part
"result"
end
m.locked? # => false
result # => "result"
//}... -
Thread
:: ConditionVariable (8074.0) -
スレッドの同期機構の一つである状態変数を実現するクラスです。
...mutex = Mutex.new
cv = ConditionVariable.new
a = Thread.start {
mutex.synchronize {
...
while (条件が満たされない)
cv.wait(mutex)
end
...
}
}
b = Thread.start {
mutex.synchronize {
#......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{
@full.wait(@mutex) if count == @max
@q.push v......end
def deq
@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 Str... -
Thread
:: ConditionVariable # broadcast -> self (8026.0) -
状態変数を待っているスレッドをすべて再開します。再開された スレッドは Thread::ConditionVariable#wait で指定した mutex のロックを試みます。
...//emlist[例][ruby]{
mutex = Mutex.new
cv = ConditionVariable.new
flg = true
3.times {
Thread.start {
mutex.synchronize {
puts "a1"
while (flg)
cv.wait(mutex)
end
puts "a2"
}
}
}
Thread.start {
mutex.synchronize {
flg = false
cv.broadcast
}... -
Thread
:: ConditionVariable # signal -> self (8026.0) -
状態変数を待っているスレッドを1つ再開します。再開された スレッドは Thread::ConditionVariable#wait で指定した mutex のロックを試みます。
...//emlist[例][ruby]{
mutex = Mutex.new
cv = ConditionVariable.new
flg = true
3.times {
Thread.start {
mutex.synchronize {
puts "a1"
while (flg)
cv.wait(mutex)
end
puts "a2"
}
}
}
Thread.start {
mutex.synchronize {
flg = false
cv.signal
}
}...