[Javascript] atomic operations

liorean liorean at gmail.com
Mon May 1 07:53:55 CDT 2006


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 "liorean" Andersson
<uri:http://liorean.web-graphics.com/>



More information about the Javascript mailing list