Skip to content

Instantly share code, notes, and snippets.

@thecodedrift
Created August 17, 2012 22:18
Show Gist options
  • Select an option

  • Save thecodedrift/3383219 to your computer and use it in GitHub Desktop.

Select an option

Save thecodedrift/3383219 to your computer and use it in GitHub Desktop.
JS Threads
var foo_count = 0;
var bar_count = 0;
var foo = function() {
++foo_count;
window.setTimeout(bar, 5);
};
var bar = function() {
++bar_count;
alert("foo="+foo_count+", bar="+bar_count);
};
// triggers
window.setTimeout(foo, 10);
window.setTimeout(bar, 20);
// end triggers
sub process
lock = get lock
if not lock owner
retry sub process in N ms (sleep)
return
lock was obtained
perform critical code
release lock
non critical segment here
end process
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment