Sleep with wakeup

I need loop in a thread (A), with a sleep, and
sometime, in another thread, wakeup A on event.

I do that, but wonder if there are not a best method
with select/mutex/conditional variable

require ‘timeout’ { loop {
ev=timeout(3) { Thread.stop ; true} rescue false
p “do work ev=#{ev} #{}”
} }

while gets
p “wakeup”

Ok, find that :

mutex =
cv = { loop {
ev=mutex.synchronize { cv.wait(mutex,4) }
p “do work ev=#{ev} #{}”
} }

while $stdin.gets
p “wakeup”
mutex.synchronize { cv.broadcast() }

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs