title: HTML5 Web Worker does not respond to message
body: <p>Consider the following code:</p>
  
  <p>worker.js</p>
  
  <pre><code>onmessage = function(evt){
      postMessage({data:"foo",id:evt.data.id});
  };
  </code></pre>
  
  <p>master.js (embedded in some HTML)</p>
  
  <pre><code>function startWorker(count){
      var running = count;
      for(var i = 0; i &lt; count; i++){
          console.log("Creating worker " + i);
          var worker = new Worker("worker.js");
          worker.onmessage = function(event){
          console.log("Worker #" + event.data.id + " finished");
          worker.terminate();
          running--;
          if(!running)
              console.log("All worker finished");
          }
          worker.postMessage({id:i});
      }
  }
  startWorker(3);
  </code></pre>
  
  <p>Whenever I execute this in <em>Chrome</em> or <em>Firefox</em>, most times I do only get the following output:</p>
  
  <blockquote>
    <p>Creating worker 0
    Creating worker 1
    Creating worker 2
    Worker #0 finished
    Worker #1 finished</p>
  </blockquote>
  
  <p>worker 2 is missing in the output, it never responds to the message. However, if I retry this for several times, a few times all workers respond to my message.</p>
  
  <p>Do you know what my problem might be? I created a <a href="http://jsfiddle.net/K3D5D/" rel="nofollow">Fiddle</a> to test this behavior.</p>