4 ms·
In the "Race Conditions? Not with Javascript!" section: > They [...] decided that no concurrency between threads is allowed, for the safety of everybody. This
by shwestrick 5y ago
In the "Race Conditions? Not with Javascript!" section:
> They [...] decided that no concurrency between threads is allowed, for the safety of everybody. This resolves the race conditions by removing the possibility that multiple threads ever run at the same time.
Nope! It's very easy to write a JS program with a race condition. Like this one, which sometimes outputs 0, sometimes 1:
var a = 0;
setTimeout(function() { a = 1; }, 50);
setTimeout(function() { console.log(a); }, 49);
- CodesInChaos 5y agoThe article should have talked about data races, which are narrower than race conditions.
- otabdeveloper4 5y agoYeah, back when I was debugging frontend bugs it seemed like at least 60% of them were race condition bugs. (It seems there's always at least one whenever a function depends on an XHR request's result.)