From: Dave Thomas Date: 2001-12-20T05:54:14+09:00 Subject: [ruby-talk:28987] Re: A Ruby programmer walked into a bar and ordered a Ruby-Thread Luc Heinrich writes: > On 19/12/2001 15:46, "Harry Ohlsen" wrote: > > > A little investigation shows that what appears to be happening is that > > the first of two threads that is created has taken complete control of > > the CPU, thus starving the main thread and not allowing any further > > processing. > > To quote the Pickaxe: > (http://www.rubycentral.com/book/tut_threads.html and page 113 of the > printed version) > > "[Ruby threads] are totally in-process, implemented within the Ruby > interpreter. That makes the Ruby threads completely portable---there is no > reliance on the operating system---but you don't get certain benefits from > having native threads. You may experience thread starvation (that's where a > low-priority thread doesn't get a chance to run). If you manage to get your > threads deadlocked, the whole process may grind to a halt. And if some > thread happens to make a call to the operating system that takes a long time > to complete, all threads will hang until the interpreter gets control back." > > So, although quite unfortunate, this would be some kind of an "expected" > behavior, I guess. Well, not really. Under Windows, there doesn't seem to be any switching between threads in some circumstances. Each thread runs to completion, and then another starts. Although arguably correct in a theoretical sense, it isn't much use in practice. Under Unix, threads play nicely with each other (hence the example with counters in the book). > Which leads me to the same question I recently asked on the #ruby-lang > channel: what kind of impact would have the introduction of native threads > in Ruby ? The interpreter is not thread safe, and the consensus seems to be that making it so would be a waste of time, given the upcoming rewrite. A secondary issue is the extensions that are already out there. How many of there are also not thread safe, and what impact would running under a native threading model have on them? Regards Dave