[whatwg] WebWorkers vs. Threads

Kristof Zelechovski giecrilj at stegny.2a.pl
Thu Aug 14 00:23:46 PDT 2008

Sorry, I do not get it.  Where does the value of (la) make it into

-----Original Message-----
From: whatwg-bounces at lists.whatwg.org
[mailto:whatwg-bounces at lists.whatwg.org] On Behalf Of Aaron Boodman
Sent: Wednesday, August 13, 2008 10:04 PM
To: Shannon
Cc: WHAT working group; Kristof Zelechovski; Jonas Sicking
Subject: Re: [whatwg] WebWorkers vs. Threads

You're right that if you try to use workers like threads, you end up
with threads. A more message-passing style implementation is easier.
In particular you would not want to allow the worker to 'get' and
'set' individual variables, but pass it messages about work you would
like it to perform, and have it pass back messages about the result.
This is less flexible than threading but easier to reason about.

// main.js
var la = 0; // what is with this variable name?
var worker = createWorker("worker.js");
worker.port.addEventListener("message", function(e) {
  la = parseInt(e.message);
}, false);

// worker.js
workerGlobalScope.port.addEventListener("message", function(e) {
}, false);

More information about the whatwg mailing list