> Writing a threads package correctly is a non-trivial thing to do.
We don't have to write a threads package.
We just have to thread the interpreter.
There's a difference.
> Perl doesn't currently run on a system that doesn't have a reasonably good
> threading library.
I abandoned an NT -> Mac port because Mac OS thread support is so
weak. And, as it happens, Mac OS only provides cooperative threads.
If Mac OS X ships before Perl6, I will concede the point.
I'm not arguing that cooperative threads are particularly desirable,
or that writing our own cooperative threading system is trivial or
specially easy.
Rather, I am pointing out that we have, in principle, two
alternatives
Plan A
Make the Perl interpreter thread-safe and run it on the preemptive
thread package provided by each platform.
Plan B
Implement cooperative threads inside the interpreter, and handle
synchronization issues by only yield()ing when it is safe to do so.
AND
I am suggesting that B may be easier to do than A. Here's an example
of why this could be the case:
Thread1 Thread2
$a = $b; $b = $a;
preemptive threading requires
- mutexes to protect $a and $b
- a robust deadlock avoidance strategy
cooperative threading requires
- don't yield inside a statement
I'd rather have preemptive threads than cooperative threads, but we
should understand
- what we are getting ourselves into
- what the alternatives are
- SWM