Ruby 2.3.0 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > Thread::ConditionVariableクラス > signal
signal -> self
[permalink][rdoc]状態変数を待っているスレッドを1つ再開します。再開されたスレッドは Thread::ConditionVariable#wait で指定した mutex のロックを試みます。
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