Connecting Tech Pros Worldwide Forums | Help | Site Map

Javascript concurrency issues...

Ben Kolera
Guest
 
Posts: n/a
#1: Jul 13 '06
As far as AJAX is concerned, I am not so concerned about the concurrent
data access problems (dining philosphers, anyone?) inherent to
multithreaded programming, but am worried, rather, about the sheer lack
of documentation detailing the behaviour of javascript in such
situations.

For example, if I have two XMLHttp objects, for which I need both
loaded to continue processing:

var XMLHttp1 = XMLHttpRequest();
var XMLHttp2 = XMLHttpRequest();

xmlHttp1.onreadystatechange= handle;
xmlHttp2.onreadystatechange= handle;

.... //snip code for sending the request

function handle() {
if(xmlHttp1.readyState == 4 && xmlHttp2.readyState == 4) {
... // snip code for continuing the processing of data
}
}

If this code was written in Java, then this code would be unsafe but I
haven't a clue as far as javascript is concerned. What constitutes as
an atomic instruction in javascript? The scary thing about it is that
it may well be very interpreter dependent... I haven't yet read the
specs for E4X, but I hope that it specifies some form of consistent
concurrency behaviour and that the browser vendors actually pay close
attention to it.

It's a problem with javascript in general, imho. I have no problems
with wonderfully abstract and expressive high level scripting languages
(big fan of Scheme :) ) but I despise all of these "magical" and quirky
undocumented behaviours that you see in languages like Javascript and
(worse still) Flash Actionscript (lol). I like to know exactly what is
going on, even if I have to read a ridiculously abstract and poorly
maintained documentation that I have to venture into dark, neglected
places of the ECMA website to find.

I realise that there is a simple way to get around this (just load them
one after the other! [since they are dependent upon each other anyway]
*gasp* how un ajax of me... i thought the goal of AJAX was to kill
browsers by opening as many threads and http connections as possible,
lol) but it just annoyed me that I had no idea of what was really going
on. I thought that I would pose the question to see if anyone knew.


Richard Cornford
Guest
 
Posts: n/a
#2: Jul 13 '06

re: Javascript concurrency issues...


Ben Kolera wrote:
Quote:
As far as AJAX is concerned, I am not so concerned about
the concurrent data access problems (dining philosphers,
anyone?) inherent to multithreaded programming,
Javascript is not multithreaded. (it is just about possible that
multiple frames may operate as multiple browser instances and for the OS
to multitask them, but there is no evidence for that being true in any
existing browsers, though an increasing use of duel core processors may
encourage browser to go in that direction).
Quote:
but am worried, rather, about the sheer lack of
documentation detailing the behaviour of javascript
in such situations.
Javascript is not multithreaded, how much else needs to be said?
Quote:
For example, if I have two XMLHttp objects, for which I need
both loaded to continue processing:
>
var XMLHttp1 = XMLHttpRequest();
var XMLHttp2 = XMLHttpRequest();
>
xmlHttp1.onreadystatechange= handle;
xmlHttp2.onreadystatechange= handle;
>
... //snip code for sending the request
>
function handle() {
if(xmlHttp1.readyState == 4 && xmlHttp2.readyState == 4) {
... // snip code for continuing the processing of data
}
}
<snip>
Quote:
... . What constitutes as
an atomic instruction in javascript?
<snip>

Executing javascript is never interrupted by event triggered (such as
onreadystatechange) code, instead the event has to wait until the
running code finishes before it can start being executed.

Richard.


Ben Kolera
Guest
 
Posts: n/a
#3: Jul 13 '06

re: Javascript concurrency issues...


<snip>
Quote:
Executing javascript is never interrupted by event triggered (such as
onreadystatechange) code, instead the event has to wait until the
running code finishes before it can start being executed.
Precisely what I needed to hear. Cheers.

- Ben

Closed Thread