Let's assume I have simple code:
var counter = 0;
var sharedResource = [];//some shared resource
function incrementAndModify(){
if(counter == 0) {
sharedResource.push(Math.random());//very sensitive data
counter++;
}
}
function init(){
incrementAndModify();
doAjaxGetWithCallback(function(){incrementAndModify();});
incrementAndModify();
}
So the question is: Will incrementAndModify()
function be run atomically or not? I've read, that JS run on single thread and there can't be any concurrency issues. But the question is still open (at least for me).
Instead of:
doAjaxGetWithCallback(function(){incrementAndModify();});
I could write something like:
doAjaxGetWithCallback(function(){
doSomeCrazyStuffThatDoesNotUseSharedResource();
incrementAndModify();
doSomeOtherCrazyStuffThatDoesNotUseSharedResource();
});