I have a thought experiment. In my code I have a global variable say var changeMe;
and I'm making few Ajax calls.
//call One -- third param is the callback function
ajaxFunction(url1, params,function(data){
changeMe = data;
});
//call Two
ajaxFunction(url2, params,function(data){
changeMe = data;
});
So changeMe
value will depend on which Ajax call finishes last, which means the call that finishes last will overwrite the value.
What if both calls finish exactly at the same time, same timestamp?
Since Javascript is single-threaded we normally won't get this problem, but this may arise in the case of setTimeout
and Ajax calls. I don't know how I can replicate this issue with precision, so it still remains a thought experiment.
So how in multi-threaded conditions is a deadlock handled?
I prefer an answer like changeMe
will be url1
or url2
, and a clear situation explanation..
Thanks in advance