stop() public

Stops execution of the current thread, putting it into a ``sleep’‘ state, and schedules execution of another thread. Resets the ``critical’‘ condition to false.

   a = Thread.new { print "a"; Thread.stop; print "c" }
   Thread.pass
   print "b"
   a.run
   a.join

produces:

   abc
Show source
Register or log in to add new notes.
October 3, 2011 - (>= v1_9_1_378)
0 thanks

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