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 :)

- One comment Not publicly viewable

  1. Brad Campbell

    Very interesting. I am just starting to look into the possibility of trying to create some boo macros to make some parallel constructs for boo. I was thinking of things like parallel for loops similar to OpenMP in Fortran. You would simply write a for loop as normal, but instead of for, maybe you name it forp. Would you be willing to share some of your code so I can learn from it?

    I’ve toyed with boo a little bit in the past but never done much with it. I’ve done quite a bit of C# and more fortran than I’d like to admit.

    Thanks,
    Brad

    29 Mar 2007, 02:45


Add a comment

You are not allowed to comment on this entry as it has restricted commenting permissions.

Google Ads

Search this blog

Most recent comments

  • I scratched my eye while i was holding some kind of plastic packaging.. Anyways the corner of the pl… by Ercan on this entry
  • About a year ago my contacts that i was wearing, i guess were fautly, because shortly after they wer… by Jon on this entry
  • I got shower gel in my eye 4 and a half days ago, and becasue i rubbed my eyes a lot, i have scratch… by Chris on this entry
  • This website may help http://www.webmd.com/eye–health/tc/Eye–Injuries–Home–Treatment by S on this entry
  • I somehow got dirt, or debris in my eye. The terrible pain sent me in a tailspin. I was afraid of sa… by Bobbi on this entry

Tags

May 2006

Mo Tu We Th Fr Sa Su
Apr |  Today  | Jun
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31            

Galleries

Blog archive

Loading…
Not signed in
Sign in

Powered by BlogBuilder
© MMXXI