るりまサーチ

最速Rubyリファレンスマニュアル検索!
36件ヒット [1-36件を表示] (0.073秒)

別のキーワード

  1. mutex_m lock
  2. mutex_m unlock
  3. mutex_m mu_lock
  4. mutex_m locked?
  5. mutex_m try_lock

ライブラリ

キーワード

検索結果

Mutex#sleep(timeout = nil) -> Integer (27132.0)

与えられた秒数の間ロックを解除してスリープして、実行後にまたロックします。

...グナルを受信した場合などに実行が再
開(spurious wakeup)される場合がある点に注意してください。

//emlist[例][ruby]{
m = Mutex.new
th = Thread.new do
m.lock
m.sleep(2)
end
th.status # => "run"
sleep
1
th.status # => "sleep"
sleep
1
th.status # => false
//}...

Thread::Mutex#sleep(timeout = nil) -> Integer (21132.0)

与えられた秒数の間ロックを解除してスリープして、実行後にまたロックします。

...グナルを受信した場合などに実行が再
開(spurious wakeup)される場合がある点に注意してください。

//emlist[例][ruby]{
m = Mutex.new
th = Thread.new do
m.lock
m.sleep(2)
end
th.status # => "run"
sleep
1
th.status # => "sleep"
sleep
1
th.status # => false
//}...

Thread::ConditionVariable#broadcast -> self (53.0)

状態変数を待っているスレッドをすべて再開します。再開された スレッドは Thread::ConditionVariable#wait で指定した mutex のロックを試みます。

...ait
で指定した mutex のロックを試みます。

@return 常に self を返します。

//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
}
}

sleep
1

# => a1
# => a1
# => a1
# => a2
# => a2
# => a2
//}...

Thread::ConditionVariable#signal -> self (53.0)

状態変数を待っているスレッドを1つ再開します。再開された スレッドは Thread::ConditionVariable#wait で指定した mutex のロックを試みます。

...ait
で指定した mutex のロックを試みます。

@return 常に self を返します。

//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
}
}

sleep
1

# => a1
# => a1
# => a1
# => a2
//}...