🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Woohoo!

Published March 08, 2009
Advertisement
I have officially run the first multithreaded Epoch application. It's a simple tweak on the old pi calculation program that I tested some time ago.

To demonstrate how easy this is, check out the code:

entrypoint : () -> (){	task(asyncjob1)	{		debugwritestring(concat("First: ", cast(string, pi(10000.0))))	}	task(asyncjob2)	{		debugwritestring(concat("Second: ", cast(string, pi(50000.0))))	}	debugwritestring("Please wait, async tasks running...")}pi : (real(denominator_limit)) -> (real(retval, 0.0)){	real(denominator, 1.0)	boolean(isplus, true)	do	{		real(div, 0.0)		assign(div, divide(4.0, denominator))		if(equal(isplus, true))		{			assign(retval, add(retval, div))			assign(isplus, false)		}		else		{			assign(retval, subtract(retval, div))			assign(isplus, true)		}		assign(denominator, add(denominator, 2.0))	} while(less(denominator, denominator_limit))}


That's it. Creating a thread and spinning off work is literally the matter of adding one keyword to a code block. Behind the scenes, the Epoch VM does all the threading magic, and away you go.

The next important piece is preventing access to global state from within tasks. In Epoch, the sole way to get data in and out of a task is to use message passing. I plan on implementing a simple lockless queue for this purpose; assuming that works as intended, the threading implementation will be 100% lock free.

Right now there's still a few lingering bugs in the thread splitting logic, especially related to tracking metadata for lexical scopes. That should prove interesting to solve.


But for now, it's time to go see Watchmen. Epoch can rest for a few hours [smile]
0 likes 5 comments

Comments

nolongerhere
Looks really good. I have been waiting for you to add the concurrent programming stuff, mostly because I have always been interested in the subject but have no knowledge about it. I do have a few questions though. Is there a way to tell when a task finishes (or all of them for that matter)? Im guessing that will have something to do with the message passing system? Also, what IS asyncjob1 and asyncjob2. Are they just names for the individual tasks or are they variables of a particular type that you just didnt show the declaration?

Cant wait to see more of this stuff. Keep it up!!!
March 08, 2009 12:15 PM
evolutional
Very nice. Tell me, have you seen the automatic threading in .NET 4? The parallel task library stuff would be perfect here.
March 08, 2009 01:17 PM
ApochPiQ
Quote: Original post by Falling Sky
Looks really good. I have been waiting for you to add the concurrent programming stuff, mostly because I have always been interested in the subject but have no knowledge about it. I do have a few questions though. Is there a way to tell when a task finishes (or all of them for that matter)? Im guessing that will have something to do with the message passing system? Also, what IS asyncjob1 and asyncjob2. Are they just names for the individual tasks or are they variables of a particular type that you just didnt show the declaration?

Cant wait to see more of this stuff. Keep it up!!!


I will be adding several features to deal with tasks, including a mechanism to wait until a task is finished. Message passing will be deeply integrated with this system.

asyncjob1 and asyncjob2 are variable names. The idea is that the task() function is actually a constructor that binds the following code block to a new system thread. Referring back to that task will be done using the variable name, for doing things like passing the task messages or retrieving messages sent by the task.


Quote: Original post by evolutional
Very nice. Tell me, have you seen the automatic threading in .NET 4? The parallel task library stuff would be perfect here.


Haven't seen any of .Net 4 actually; got any good resources covering the automatic threading stuff?
March 08, 2009 01:59 PM
choffstein
Have you taken a look at Clojure's threading paradigm? It is pretty interesting, and might give you a couple ideas...
March 08, 2009 02:22 PM
evolutional
Quote: Original post by ApochPiQ
Haven't seen any of .Net 4 actually; got any good resources covering the automatic threading stuff?


Take a look at the microsoft news article here. It's pretty funky.
March 08, 2009 06:00 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement