This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// An example race condition in JavaScript | |
// When you run this script using Node or in a browser, you'll find it | |
// does not print "Ended with 0", but a random number. Even though the functions running | |
// simply loop 100 iterations of adding and subtracting. The reason the end result is random | |
// is because the sleeps are of random duration and the time between the read of the variable | |
// causes the eventual write to be incorrect when `adder` and `subber` interleave. | |
// This problem is similar to https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use | |
let number = 0; | |
const times = 100; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var out="["; | |
for(var indx=0;indx<data.length-1;indx++){ | |
out+=JSON.stringify(data[indx],null,4)+","; | |
} | |
out+=JSON.stringify(data[data.length-1],null,4)+"]"; |