[Stackless] Mixing os threads and stackless
lars at ibp.de
Wed Apr 26 15:56:03 CEST 2006
> Also, I might need to correct myself, I meant Python thread, not OS
> (Not sure that that distinction matter, as I understand it, OS threads
> (created in C for instance) needs to be made into Python threads to be
> used anyway!?)
A Python thread (created from C with pthread_create or beginthread, or
through the threading or thread module) *is* an OS thread with a
A thread created through the threading module has a bit more per-thread
state information, but for the most part, it is just an OS thread.
And these threads, by virtue of having separate stacks, can call
separate, blocking, C functions at the same time. So they could both be
in a socket.recv() at the same time, for example.
A stackless tasklet is *not* an OS thread, and all tasklets share a
single C stack.
As a consequence, two cannot be in a socket.recv() at the same time.
This isn't necessarily a problem, mind you, because sockets can be
non-blocking, for example, or, better, you hide a reactor (something
that does a poll() or select() and demultiplexes events) in your
stackless application and use the stacklet channel primitives to
dispatch the events.
Stackless mailing list
Stackless at stackless.com
More information about the Stackless