4 ms·
And it doesn't actually prevent concurrency.
by Kinrany 6mo ago
And it doesn't actually prevent concurrency.
- gf000 6mo agoSure, but concurrent != parallel. You can't have data races with a single thread of execution - a while loop writing i=0 or i=1 on each iteration is not a data race. Two async functions doing so is not a data race either.
- gpderetta 6mo agoData race != Race condition
- gf000 6mo agoData races are a specific race condition - they may be safe or cause tearing. Serially, completely synchronously overwriting values is none of these categories though.
- Maxatar 6mo agoYou're mixing up quite a few somewhat related but different concepts: data races, race conditions, concurrency and parallelism. Concurrency is needed for race conditions, parallelism is needed for data races. Many single threaded runtimes including JS have concurrency, and hence the potential for race conditions, but don't have parallelism and hence no data races.
- gf000 6mo agoConcurrency with a single thread of execution runs with complete mutual exclusion, so no "pure" single threaded concurrency is definitely race condition free. What we may argue over (and it becomes more of a what definition to use): IO/external event loop/signal handlers. These can cause race conditions even in a single threaded program, but one may argue (this is sort of where I am) that these are then not single threaded. The kernel IO operation is most definitely not running on the same thread of execution as JS. I think I have been fairly consistent in the definition of a data race as a type of race condition, where a specific shared memory is written to while other(s) read it with no synchronization mechanism. This can be safe (most notably OpenJDK's implementation is tear-free, no primitive or reference pointer may ever be observed as a value not explicitly set by a writer), or unsafe (c/c++/rust with unsafe, surprisingly go) where you have tearing and e.g. a pointer data race can cause the pointer to appear as a value that was never set by anyone, causing a segfault or worse.
- Kinrany 6mo agoYou can implement your own event loop within a single thread
- Rapzid 6mo agoYou should really look up the definition of race condition; it has nothing to do with parallel processing. Parallel processing just makes it harder to deal with.