Thread#run和Thread #wakeup之间的区别?
在Ruby中, Thread#run和Thread#wakup有什么区别 ?
RDoc指定不使用Thread#wakeup调用调度程序 ,但这意味着什么? 什么时候使用wakeup vs run ? 谢谢。
编辑:
我看到Thread#wakup导致线程变为可运行,但是如果在执行Thread#run之前它不会执行它会有什么用处(无论如何唤醒线程)?
有人可以提供一个醒来有意义的例子吗? 出于好奇心的缘故=)
这是一个例子来说明它的含义( 这里的代码示例):
Thread.wakeup
thread = Thread.new do Thread.stop puts "Inside the thread block" end $ thread => #
上面的输出表明由于stop命令,新创建的线程处于睡眠状态。
$ thread.wakeup => #
此输出表明线程不再处于hibernate状态,并且可以运行。
$ thread.run Inside the thread block => #
现在线程继续执行并打印出字符串。
$ thread.run ThreadError: killed thread
Thread.run
thread = Thread.new do Thread.stop puts "Inside the thread block" end $ thread => # $ thread.run Inside the thread block => #
线程不仅会唤醒,还会继续执行并打印出字符串。
$ thread.run ThreadError: killed thread