method
stop
v2_6_3 -
Show latest stable
- Class:
Thread
stop()public
Stops execution of the current thread, putting it into a “sleep” state, and schedules execution of another thread.
a = Thread.new { print "a"; Thread.stop; print "c" } sleep 0.1 while a.status!='sleep' print "b" a.run a.join #=> "abc"
1Note
example will not work in 1.9+
Since 1.9 introduces native threads, we cannot assume the order of exectution and the example above is not thread safe and fails with a "deadlock detected (fatal)" error. Also Thread.pass is pointless in the context of native threads.
This will work as intended with native threads:
a = Thread.new { print "a"; Thread.stop; print "c" }
sleep(0.1) until a.status == 'sleep'
print "b"
a.run
a.join