[Stackless] tasklets on threads
Kristján Valur Jónsson
kristjan at ccpgames.com
Fri Sep 9 22:28:00 CEST 2011
Idle means idle.
When the last runnable tasklet on a thread becomes blocked, that whole thread goes to sleep, and is blocked on a lock waiting to be reawoken. This happens when one unblocks a tasklet on the thread, e.g. by sending on a channel.
It's useful to know if a thread is in such a state, rather than busy, for example, having relinquished the GIL in order to do IO.
Of course, it is possible to do it differently, by having each thread only perform one task at a time, and then just checking if someone is listening on the other end of the receiving channel. But knowing about the idleness state of the thread, it's possible to select a target thread that is, well, idle.
From: stackless-bounces at stackless.com [mailto:stackless-bounces at stackless.com] On Behalf Of Jeff Senn
Sent: 9. september 2011 19:04
To: The Stackless Python Mailing List
Subject: Re: [Stackless] tasklets on threads
On Sep 9, 2011, at 2:37 PM, Kristján Valur Jónsson wrote:
> Hm, you are probably right. Maybe Im just fussing about. I'll have to go and investigate some more.
> Btw, all of this comes from a desire to hand off jobs to tasklets on other threads. What I am aiming to add is a way to figure out if that thread is "blocked", i.e. that it is waiting for stuff to do. Since tasklets are associated with threads, my current idea is to add an attribute to tasklets, something like tasklet.idle, which would be True if that tasklet's thread is idle. A pool of such threads could then be maintained and a job can be handed off to one of them, depending on their idlestate, using channels. No need to mess around with locks and condition variables and whatnot.
Hm. That doesn't sound possible (without causing some race condition to be present) -- unless you mean, by "idle", something more like "might still be idle by the time I get around to sending it a message"... that seems of limited utility for basic load balancing, or in a 1-producer-N-consumer situation...
Stackless mailing list
Stackless at stackless.com
More information about the Stackless