Re: Workers

Ian Hickson wrote:
>   
> Due to popular demand, I have written a new specification for Workers:
>  
>    http://www.whatwg.org/specs/web-workers/current-work/
>
>
> On Wed, 9 Jul 2008, Andrew Fedoniouk wrote:
>   
>> Ian, as far as I understand that is primarily about network 
>> communications? If yes then what is conceptually wrong with asynchronous 
>> http data requests (a.k.a. AJAX) we have now?
>>     
>
> It's about background computation, background syncing of client-side and 
> server-side databases, and other such tasks.
>
>
>   
>> If it is about coroutine alike things then 'yield' feature in JS 
>> probably will be enough, no?
>>
>> To be short what is the motivation of js-threads?
>>     
>
> One example from Google's stable would be separating the UI and the 
> low-level networking and database access in GMail: it would be cool if 
> instead of having everything running on the same thread, the UI could just 
> post messages to a background thread that did all the real work.
>   

Just for brevity and to make it clear for myself:

(All this is about preemptive multitasking in JS)

1) WindowWorker (why it is "window" btw?) is a separate instance of  
JavaScript VM (virtual machine)
2) Such an instance is created on demand by the script running in main 
UI thread - "initiator".
3) Communication between different JS VMs (and so with initiator) 
happens through message queues.
4) Message queue is a FIFO list of DOM events and timer callbacks. (DOM 
event as an object can carry
    various user defined sub objects. Timer callback if it is a local 
function can carry many things too.)

Questions:
0) Are the statements above correct ones?
1) It appears that such VMs have access to the same DOM. How 
synchronization of access to the DOM happens then?
2) It appears 
(http://www.whatwg.org/specs/web-workers/current-work/#processing)
as all VMs are capable to share other objects like opened databases. 
What about synchronization of method calls?
3) It is not clear how Workers receive DOM events and which ones by the way?
4) It is not clear how messaging happens between different threads (JS 
VMs).  Say how following can be accomplished:

script on the page (main UI thread) ---------------

var message = { type: "simple"; data: 28; }
var some_thread = new Thread("script.url");
     some_thread.port.post( message );

worker ---------------

function do_something_with(message) {  ... }
self.port.onMessageArrived( do_something_with ) ; // event alike 
asynchronous thing

//-- or is it like this ---

var message = waitUntilNextMessage(); // blocking function.
do_something_with(message);

?

It really makes sense to provide sample JS code of how typical Worker 
script looks like. Will help to understand all this better.

I thought initially that worker threads will be completely isolated from 
the DOM and so from DOM events and so from each other. But it appears as 
authors have different opinion on that.

Thanks in advance for the clarification.

--
Andrew Fedoniouk.

http://terrainformatica.com

Received on Friday, 18 July 2008 19:09:19 UTC