by ChrisSD · 8y ago · 0 comments
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.
Are you sure about this ? I could not find anywhere something saying that the main JS execution would switch threads - and even if it did, it would not impact the observable behaviour of your JS code anyways. Everything I could find on google says "JS is single-threaded" (except for web workers of course).
Is this page wrong ? : https://itnext.io/how-javascript-works-in-browser-and-node-a... and do you have an example of problematic code ?
With such a definition of multithreaded language wouldn't Brainfuck also be one?