On Wed, 16 Jan 2002, Markus Jais wrote:
> this is more of a general question on Ruby Threads. I have never used
> threads in any language until now, so I am a complete newbie to this
> topic. (have read something about threads in a bad java book, but this
> didn't help me with the following questions)

You can't find the truth in a bad java book any more than by watching
infomercials.

> I read somewhere that Ruby threads are no native threads.

That's still true. Matz mentioned native threads for 2.0.

> what exactly is a native thread?? (something using pthreads on linux??)

AFAIK, pthreads are "abstract" threads, and are implemented as native
threads on Linux, but then, I could be wrong (i haven't used them myself).
If not you can create your own native threads by using fork() for
splitting processes and mmap() for sharing memory.

> what is the advantage / disadvantage of the ruby approach to threads??
> are native threads faster??

ruby threads are "user threads" (or "user-mode threads"), and they're also
"cooperative". "User" means does not involve the kernel more than strictly
necessary (maybe just for a timer). "Cooperative" means that the scheduler
is not invoked by the timer, but instead the timer notifies the running
thread, which must switch to the scheduler task. This require less locking
mechanisms at the low level, which may be faster, because locking takes
time continuously, and other reasons. OTOH it's less smooth unless you
really insert a lot of those "if (time_expired) switch_threads();"
statements in every place that may take a non-small amount of time to run.

> Does anybody know, if the Python and Perl Thread implementations are similar
> to the ruby Thread implementation??

Perl uses a different model. I think it's using one interpreter per
thread, possibly using kernel threads. I don't know the details.

________________________________________________________________
Mathieu Bouchard                   http://hostname.2y.net/~matju