[Javascript] atomic operations

Matt Warden mwarden at gmail.com
Mon May 1 09:37:47 CDT 2006


On 5/1/06, liorean <liorean at gmail.com> wrote:
> On 30/04/06, Matej Kovac <matej at pobox.sk> wrote:
> > I have came across need to lock an object in javascript function
> > called from multiple event handlers or timers. is there some
> > atomic operation in javascript? is the ++ operator atomic? or is
> > the Array.push() atomic? is there some safe semaphore or mutex
> > like operation which can be used in standard browsers without java?
>
> The JavaScript engines in all browsers are single threaded, and the
> language lacks any kind of multithreading support. Only one script
> body is ever executed at any one time. So multiple events, timeouts
> etc. will all be scheduled for execution one after the other, and they
> will all be performed in their entirety before the next one will start
> executing.
>
> In other words, you shouldn't have to worry about threading in JavaScript.

David,

This is interesting and, while it makes perfect sense, I don't think
many developers keep this in mind with the current ideas about
asynchronous programming. I was worried about m-threading issues when
I was working on an object that would abstract multiple
xmlhttprequests as a single two-way connection, and obviously I was
much worried about nothing.

Do you (or anyone else) have a reference for this information that I
could point to in the source of my lib?

Thanks,

--
Matt Warden
Miami University
Oxford, OH, USA
http://mattwarden.com


This email proudly and graciously contributes to entropy.



More information about the Javascript mailing list