4 ms·
Even loop is not concurrency. Just because concurrency and parallelism are different does not meant that concurrency and event loops are the same.
by pizlonator 9y ago
Even loop is not concurrency.
Just because concurrency and parallelism are different does not meant that concurrency and event loops are the same.
- christophilus 9y agoYou can build concurrency on the event-loop, though, which is what the OP was probably referring to.
- pizlonator 9y agoNot quite. Consider a component in your code that does this: for (let blah of things) foo(blah); In an event loop, if things has a lot of stuff in it, this can block the event loop. Other things in the event loop won't be able to run until this completes. With threads, this just works.
- enoah_netzach 9y agoThat is parallelism, not concurrency. Concurrency: two functions can run one after the other while they are non blocking for the callers (e.g. hyperthreading). Parallelism: two functions can run at the same time (e.g. multiple processors).
- pizlonator 9y agoYour definition of concurrency is not correct. Concurrency usually implies that the work is chopped up into very small interleavable bits. A while function call with a loop of unbounded length being the default granule of interleaving is definitely not part of the definition of concurrency. The term "concurrency" subsumes both event loop style concurrency and two-cores-running-code-at-the-same time concurrency.
- Jtsummers 9y agoYes, it is. The JavaScript event loop is a very lazy scheduler than does no preemption. It's a very primitive concurrency model. It's up to the users of the language to break their tasks down into sufficiently small components or yield to allow for interleaving of work.
- deleted 9y ago[deleted]
- skybrian 9y agoCreating async tasks that can run concurrently and deliver progress via events is a concurrency model.
- loftyal 9y agoHow? Explain please. https://en.wikipedia.org/wiki/Concurrency_(computer_science) https://en.wikipedia.org/wiki/Concurrency_(computer_science) "order-independent components", which makes sense for the Event loop.
- pizlonator 9y agoI draw the line at whether the interleaving granule is under the programmer’s control or not. For example, I can say that when a task executes on an event loop, no other tasks are executing concurrently to it because the event loop executes tasks sequentially.
- loftyal 9y agoOk you draw the line there, but definitions are supposed to be commonly understood, that's how language works...
- pizlonator 9y agoYeah, I agree it would be better if people in the event loop community learned to use the word “concurrency” correctly.