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?
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?
Share Improve this question edited May 24, 2016 at 22:31 Gaël Barbin asked Jan 18, 2012 at 23:18 Gaël BarbinGaël Barbin 3,9393 gold badges31 silver badges52 bronze badges2 Answers
Reset to default 3Javascript 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.
Yes. concatenation is an atomic operation in Javascript.