# JS-Interpreter Thread Demo

Creating two or more completely independent threads that run separately from each other is trivial. Just create two instances of the Interpreter, each with its own code, and alternate calling each interpreter's step function.

This demo illustrates the slightly harder problem of creating two threads that share the same global environment. This allows one to share functions and variables, as well as to communicate between threads.

1. Click Parse on thread #1, then click Step repeatedly until one gets past the var line.
2. Click Parse on thread #2, then click Step repeatedly to alert the value of 'foo'.
3. Continue clicking Step repeatedly on either thread to set or read 'foo'.

Open your browser's console for errors.

Thread #1 | Thread #2
var foo = 0; while(true) { foo++; } | while(true) { alert(foo); }

Back to the JS-Interpreter documentation.