I'm working with some code that does this:
var _init = false;
this.init = function(){
if(_init)
return;
else
_init = true;
// Do a bunch of stuff here
}
It seems to me that there is a tiny race condition there that I'd like to eliminate. It's possible for a second instance of the init
function to start running before the first instance has gotten around to setting _init
to true. Unlikely, but non-zero, yes?
Given that, is there a straightforward way to eliminate this race condition short of something like a Singleton pattern?