by otabdeveloper1 · 8y ago · 0 comments
Seems to me that something like 50% of clientside Javascript coding is "worrying about hard-to-trace race conditions", so maybe that's a feature, not a bug.
Say, you have a code like this:
asynchronously doA();
blockReadingFile();
doB();
Whether doA() is finished or not when doB() executes depends on internals of doA() and on how long blockReadingFile() takes.1. Reentrancy. Flow of tasks can be interrupted by hardware interrupts and OS signals. In that case race conditions can happen by interrupt handlers. Bare metal embedded system programmers often have big headaches because of this.
2. JS implementations and JS API design can have race condition bugs. So JS API designers have to consider it. One of example is because of the order of queuing tasks/handlers. [1]
[1]: https://github.com/w3c/mediacapture-record/issues/150#issuec...
asynchronicity and parallelism (threads) are two entirely different concepts. Most GUI systems except BeOS's are asynchronous on a single thread. When you code in node you just have one big hidden while loop that does
while(true) {
doPostedEvents();
}
and executes your callbacks one after each other.They are. However, in the browser resources (such as scripts) will be loaded using multiple threads. Javascript will be executed on one thread at a time, but this execution will switch to another context at the appropriate breakpoints.
Javascript in the browser is a multithreaded cooperatively multitasking system.