Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How a concurrent access of a variable is managed in javascript

I'm working on a chrome extension, which use asynchronous functions, and I have a global string variable which is set by a function, like that:

my_global_variable += a_string

I would know if there is a risk that, if I read my_global_variable in another function at the same time, I got just a portion of a_string.

In other words, does the concatenation ( more generally an instruction) is an atomic operation?

like image 407
Gaël Barbin Avatar asked Jan 18 '12 23:01

Gaël Barbin


1 Answers

Javascript in the browser is singled threaded (unless using HTML5 Web Workers) so there is no contention around variable access. There was threading in Chrome via the Gears plugin but that has been discontinued in favour of HTML5 functionality e.g. Web Workers.

like image 179
David Clarke Avatar answered Sep 21 '22 16:09

David Clarke