3

We can create a new instance of a web worker as such:

var worker = new Worker('task.js');

Are each web worker backed by its own native thread, or is there a pool of native threads allocated per window which all web workers of that window will then share?

Are there standard implementation guidelines that browsers are supposed to follow?

What about the state of popular browsers like Chrome, FireFox, etc?

Community
  • 1
  • 1
Pacerier
  • 86,231
  • 106
  • 366
  • 634

1 Answers1

7

The W3C standard says this about Web Workers execution context:

Create a separate parallel execution environment (i.e. a separate thread or process or equivalent construct), and run the rest of these steps asynchronously in that context.

Essentially, a browser can implement this however it pleases. Any, or all, or none of your suggestions may apply.

Here's the reference: http://www.w3.org/TR/workers/

  • But the wording is extremely vague: When they talk about a "separate thread", do they mean a "separate green thread" or a "separate red thread"? And "asynchronously" is of course, even worse. We could do *asynchronous* scripting via good old `setTimeout` as well.. – Pacerier May 02 '14 at 08:07
  • 2
    The specification doesn't even specify that a separate thread be used, just that a separate asynchronous context be established. The distinction between green or red threads, or no separate thread at all, is a matter for the browser implementation. –  May 02 '14 at 08:10