Skip to content

Instantly share code, notes, and snippets.

@ashanbh
Created June 5, 2013 07:31
Show Gist options
  • Save ashanbh/5712199 to your computer and use it in GitHub Desktop.
Save ashanbh/5712199 to your computer and use it in GitHub Desktop.
var globalObject =0;
function incInf1500(time){
return function(){
var local = globalObject;
console.log("Start "+time+ " : "+local);
setTimeout(function(){
globalObject=local+1;
console.log("End "+time+ " : "+globalObject);
},1500);
}
}
setInterval(incInf1500("t2"),5000)
setInterval(incInf1500("t1"),5000)
//race Conditions will Occur
//Start t2 : 0
//Start t1 : 0
//End t2 : 1
//End t1 : 1
//Start t2 : 1
//Start t1 : 1
//End t2 : 2
//End t1 : 2
// Which makes me question http://ejohn.org/blog/how-javascript-timers-work/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment