最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

google chrome - How a concurrent access of a variable is managed in javascript - Stack Overflow

programmeradmin1浏览0评论

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 badges
Add a ment  | 

2 Answers 2

Reset to default 3

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.

Yes. concatenation is an atomic operation in Javascript.

发布评论

评论列表(0)

  1. 暂无评论