Microthreads: wait( duration ) with minimal processor overhead, u

Will Ware wware at world.std.com
Sat May 27 09:37:00 EDT 2000


Courageous (jkraska1 at san.rr.com) wrote:
> Eh? These are *microthreads*. Using thousands and thousands
> of "normal" threads will clobber your cpu. And yet in a very
> simple test of microthreads, I was able to spawn up 10,000 of
> them and watch them finish in under 3 seconds flat. Quite
> remarkable.

When I said "normal sleeping threads", I was unclear. I wasn't
referring to sleeping OS threads (e.g. Posix threads), I meant
"sleeping microthreads as they are already implemented in uthread4.py".

I thought he was working on a non-problem, since we had gone to
some pains to ensure that the kinds of threads I mentioned didn't
poll. It turns out, however (and this is the issue he was actually
addressing), timers and queues that are blocking user threads maintain
internal threads to poll the condition which will unblock the user
threads.

> I'll be a monkey's uncle if the author of the uthread library
> doesn't know all about how normal threads work...

Originally I hacked together an early microthread implementation by
editing the code in eval.c. Several people pointed out that the
much cleaner approach was to use Chris Tismer's stackless Python
(which, to this day, contains deep dark mysteries beyond my mortal
ken). Eventually the two converged, and a little later Just stepped
in and made the whole thing even cleaner and more idiomatically
Pythonic. By now, I'm a symbolic figurehead, relegated to cutting
ribbons at the openings of shopping malls.
-- 
 - - - - - - - - - - - - - - - - - - - - - - - -
Resistance is futile. Capacitance is efficacious.
Will Ware	email:    wware @ world.std.com



More information about the Python-list mailing list