Standard Threads vs Weightless Threads

Christopher Subich spam.csubich+block at block.subich.spam.com
Mon Aug 1 09:46:16 EDT 2005


yoda wrote:
> 1)What is the difference (in terms of performance, scalability,[insert
> relevant metric here]) between microthreads and "system" threads?

System-level threads are relatively heavyweight.  They come with a full 
call stack, and they take up some level of kernel resources [generally 
less than a process].  In exchange, they're scheduled by the OS, with 
the primary benefit (on uniprocessor systems) that if one thread 
executes a blocking task (like IO writes) another thread will receive 
CPU attention.

The primary disadvantage is that they're scheduled by the CPU.  This 
leads to the concurrency nightmare, where the developer needs to keep 
track of what blocks of code (and data) need locks to prevent deadlock 
and race conditions.

> 
> 2)If microthreads really are superior then why aren't they the standard
> Python implementation (or at least within the standard library)? (where
> my assumption is that they are not the standard implementation and are
> not contained within the standard library).

Microthreads are very different; they're entirely internal to the Python 
process, and they're not seen at all by the operating system. 
Scheduling is done explicitly by the microthread implementation -- 
multitasking is not preemptive, as with system threads.

They're not in the standard library because implementing microthreads 
has thus far required a very large rewrite of the CPython architecture 
-- see Stackless Python.



More information about the Python-list mailing list