All 1 entries tagged Threading
No other Warwick Blogs use the tag Threading on entries | View entries tagged Threading at Technorati | There are no images tagged Threading on this blog
May 24, 2006
Light weight threading
I'm experimenting with light weight threads in Boo. I have an AST attribute that duplicates a method and inserts "yield" statements between each statement. This makes the method into an iterator that can be stepped through. I have a scheduler class that takes a list of methods and effectively runs them concurrently – but without all the heavy weight OS context switching.
Here is sample output from a demo program:
2 Processors
3000 Threads
Light weight threads:
Done in 45 milliseconds
.NET threads:
Done in 50236 milliseconds About 1000 times faster!!
Note that I have two processors so the light weight scheduler actually creates two OS threads on which to run the light weight ones. This makes maximum use of my machine!
The code being run by the thread is in this class:
class Dog():
energy as int
def Eat():
energy++
def Bark():
energy--
[LightWeightThreadMethod]
def Live():
for i in range(100):
Eat()
Bark() So basically I'm saying create 3000 dogs and run them all at once! Normal threads crawl due to the huge amount context switching. Light weight threads work like a dream :)
Please wait - comments are loading

Loading…

