Implementing Mutual Exclusion for AJAX
Subject:   Browser Javascript implementations are single threaded...
Date:   2006-04-06 07:19:33
From:   jdodds
Response to: Browser Javascript implementations are single threaded...

"Browser JavaScript implementations are single threaded" is, unfortunately, not actually a true statement.

Microsoft Internet Explorer (surprise, surprise) breaks the single threaded JavaScript model. Many of the host objects in IE are implemented as COM objects and Microsoft did not architect the integration in a way that protects the integrity of the JavaScript language. Hence you have issues like closures that capture DOM objects leaking memory. It also means that callbacks into JavaScript from COM objects are usually on a different thread, the thread that's running inside the COM object.

I haven't had to deal with these kind of issues for a while but my possibly faulty recollection is that setTimeout() will perform a thread context switch. So the onreadystatechange handler should not directly operate on a request result but instead should package the result in a closure and then use setTimeout to push processing back onto the primary JavaScript thread.

1 to 1 of 1
1 to 1 of 1