Javascript thread-handling and race-conditions
Lets asume I have a code like the following: var shared = 100; function workWithIt(){ shared += 100; } setTimeout(workWithIt, 500); setTimeout(workWithIt, 500); Ideally, this piece of code should add 200 to the variable shared , which is 300 afterwards. But, as I know from c , there can be some implications, if the operation += is split into multiple commands. Lets say, that this is the execution-order of the function: setTimeout() --> create Thread A setTimeout() --> create Thread B wait 500ms **Thread A** | **Thread B** --------------------------------+--------------------------------- var