title: Is localStorage thread safe?
body: <p>I'm curious about the possibility of damaging <code>localStorage</code> entry by overwriting it in two browser tabs simultaneously. Should I create a mutex for local storage?<br>
  I was already thinking of such pseudo-class:</p>
  
  <pre><code>LocalStorageMan.prototype.v = LocalStorageMan.prototype.value = function(name, val) {
    //Set inner value
    this.data[name] = val;
    //Delay any changes if the local storage is being changed
    if(localStorage[this.name+"__mutex"]==1) {
      setTimeout(function() {this.v(name, val);}, 1);
      return null;  //Very good point @Lightness Races in Orbit 
    }
    //Lock the mutext to prevent overwriting
    localStorage[this.name+"__mutex"] = 1;
    //Save serialized data
    localStorage[this.name] = this.serializeData;
    //Allow usage from another tabs
    localStorage[this.name+"__mutex"] = 0;
  }
  </code></pre>
  
  <p>The function above implies local storage manager that is managing one specific key of the local storage - <code>localStorage["test"]</code> for example. I want to use this for greasomonkey userscripts where avoiding conlicts is a priority.</p>