You Are Here Home > Basic threading in JavaScript; multiple threads of...

Basic threading in JavaScript; multiple threads of execution in JavaScript

I was searching the web yesterday for this and didn’t really find a simple way of doing this and suddenly, I remembered something.

It’s extremely simple, someone could build on it with all sorts of features but for now, here is an example:
http://images.code-head.com/code/javascript/js-threads.html

As you can see there are two counters, one is counting up and the other down simultaneously.

Here is the start_thread function:

             function thread_start(callback) {
		setTimeout(callback, 1);
		return true;
	}

The trick is that setTimeout *does not* block the execution ;)

I hope this helps someone :)

Basic threading in JavaScript; multiple threads of execution in JavaScript
Filed under: Fun, General, JavaScript, Programming, jQuery   Posted by: Codehead on June 30, 2009

Disclaimer
1 - Use the information provided here at your own risk.
2 - You may not republish this content without prior written consent.




1 Comment »

  1. Yussuf Shaikh Ibrahim:
     

    THANK YOU..m proud of u…!!! :)
    ya it helped me

    Comment — December 24, 2009 @ 2:53 am

RSS feed for comments on this post. TrackBack URL

Leave a comment