http://zhangyu8374.iteye.com/blog/86299
Green Thread 不比Native Thread 差
在Ruby实现中,Ruby1.8采用的是
Green
thread ,JRuby和XRuby采用的是Native
thread ,Rubinius既支持
Green
thread ,也支持Native
thread 。Ruby1.9将由
Green
thread 转向Native
thread 。
Green
thread 有哪些不足呢?
在“ Ruby Userspace Thread s vs GUI tookits Roundup ”中重点强调了 Green Thread 的一个不足:Blocking syscall将阻塞所有其余的线程,而且这个问题在GUI和网络开发中将随处碰到。另外, Green Thread 不能有效挖掘多核和多CPU的性能。于是大家都把视线转向Native thread 。我对Native thread 不感冒,主要是因为shared state concurrency问题多多。具体有哪些,相信你看完“ The problem with thread s ”就会很清楚了。
现在,Erlang很好的解决了 Green Thread 存在的问题。它没有采用m:1模式,而是采用了m:n模式。Erlang runtime以n个native thread 运行,每个都有一个自己的调度器。而且,Erlang采用shared nothing concurrency,可以把Native Thread 存在的问题都抛之脑后。
看来XRuby的 thread 实现可以好好借鉴一下Erlang的并发范式。在看了“ The Futures of Ruby Thread ing ”之后,更坚定了应该朝这方面努力。
在“ Ruby Userspace Thread s vs GUI tookits Roundup ”中重点强调了 Green Thread 的一个不足:Blocking syscall将阻塞所有其余的线程,而且这个问题在GUI和网络开发中将随处碰到。另外, Green Thread 不能有效挖掘多核和多CPU的性能。于是大家都把视线转向Native thread 。我对Native thread 不感冒,主要是因为shared state concurrency问题多多。具体有哪些,相信你看完“ The problem with thread s ”就会很清楚了。
现在,Erlang很好的解决了 Green Thread 存在的问题。它没有采用m:1模式,而是采用了m:n模式。Erlang runtime以n个native thread 运行,每个都有一个自己的调度器。而且,Erlang采用shared nothing concurrency,可以把Native Thread 存在的问题都抛之脑后。
看来XRuby的 thread 实现可以好好借鉴一下Erlang的并发范式。在看了“ The Futures of Ruby Thread ing ”之后,更坚定了应该朝这方面努力。