I know web workers work as a separate thread than the UI thread but i dont understand why they are not allowed to modify the DOM. I mean that you can allow inter thread communication and keep the DOM data in a shared space and have the web workers thread modify the DOM. Why is this not allowed in browsers?
            Asked
            
        
        
            Active
            
        
            Viewed 1,495 times
        
    3
            
            
        
        lovesh
        
- 5,235
 - 9
 - 62
 - 93
 
- 
                    1It happens on almost every programming language that does GUI: only the main thread can call GUI functions (eg: Android, Delphi) – LatinSuD Dec 27 '12 at 08:10
 
1 Answers
7
            Because the DOM is not threadsafe, and JavaScript does not expose a thread API.
See also:
- 
                    1_"A piece of code is thread-safe if it can be safely invoked by multiple threads at the same time."_ http://en.wikipedia.org/wiki/Thread_safety – Matt Ball Aug 16 '11 at 17:25
 - 
                    can you tell me some references where i can read more about thread safety of DOM? thanks – lovesh Aug 16 '11 at 17:40
 - 
                    1It's not thread safe, and was never intended to be, since ***JavaScript does not have any concept of a thread*** or other concurrent/parallel constructs. That's it. – Matt Ball Aug 16 '11 at 17:56