Created
June 5, 2013 07:31
-
-
Save ashanbh/5712199 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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