[whatwg] providing a DOM API to workers without a thread-safe DOM implementation

Ian Hickson ian at hixie.ch
Wed Dec 9 10:55:21 PST 2009


On Wed, 9 Dec 2009, David Bruant wrote:
> Ian wrote:
> >
> > Since browsers don't have thread-safe DOM implementations, that's 
> > basically a non-starter. It doesn't matter that we aren't offering 
> > access to the same DOM in pages and workers; the actual innards of the 
> > DOM implementations aren't thread safe.
> > 
> > As soon as browsers are able to implement this, I'm sure it will be 
> > added to the spec.
>
> The point of my "Re: [whatwg] [WebWorkers] Advocation to provide the DOM 
> API to the workers" e-mail of the December 7th was to prove that we 
> don't even need a thread-safe implementation.

When I am referring to thread safety here I don't mean that it's not 
possible for a single DOM tree to be accessed from two threads. I mean 
that it's not possible for two DOM nodes from completely unrelated trees 
to exist on two threads, because the DOM implementations make use of 
global state (e.g. global atoms, memory pools) that are not written such 
that they can be accessed from code in multiple threads (e.g. because the 
memory allocator doesn't use locks to ensure that the memory pool is only 
mutated by one thread at once).


> The requirement is just to have 2 implementations (which can be the 
> same, but it would be a "coincidence") one for the main browsing 
> context, the other for workers.

Whether it's a second implementation or one implementation that is made 
thread-safe, UAs don't currently have it. As soon as they do, we'll be 
able to add DOM APIs to workers.


> Then, I'm describing a way to communicate (through postMessage and the 
> onmessage handler) which allow to send and recieve DOM objects 
> (Node/Element/Document/DocumentFragment) in a safe way (basically, by 
> breaking the references to DOM objects coming from another 
> implementation and I think that I have enumerated all of them and found 
> a proper solution for each).

This is not the problem.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'



More information about the whatwg mailing list