On Mon, Mar 31, 2003 at 08:13:09PM +0200, Matthijs van Duin wrote:
> I think we should consider cooperative threading, implemented using 
> continuations.  Yielding to another thread would automatically happen when 
> a thread blocks, or upon explicit request by the programmer.
> 
> It has many advantages:

It has major disadvantages:

I must write my code so each operation only takes a small fraction of time
or I must try to predict when an operation will take a long time and yield
periodicly.

Worse, I must trust that everyone else has written their code to the above
spec and has accurately predicted when their code will take a long time.


Cooperative multitasking is essentially syntax sugar for an event loop.  We
already have those (POE, Event, MultiFinder).  They're nice when you don't 
have real, good preemptive threads, but cannot replace them.  It is a great
leap forward to 1987.

The simple reason is that with preemptive threads I don't have to worry 
about how long an operation is going to take and tailor my code to it, 
the interpreter will take care of it for me.  All the other problems with 
preemptive threads aside, that's the killer app.


We need preemptive threads.  We need good support at the very core of the
langauge for preemptive threads.  perl5 has shown what happens when you
bolt them on both internally and externally.  It is not something we can
leave for later.

Cooperative multitasking, if you really want it, can be bolted on later or
provided as an alternative backend to a real threading system.


-- 
I'm spanking my yacht.

Reply via email to