4 ms·
I'll generally agree with your definitions for concurrency and parallelism. Our parallelism definitions were essentially the same. But what you say about coldt
by Jtsummers 9y ago
I'll generally agree with your definitions for concurrency and parallelism. Our parallelism definitions were essentially the same.
But what you say about coldtea is not a fair interpretation of their post. millstone said this:
The event loop doesn't allow you to do a computation
concurrently with handling user events, so it's not at
all a proper concurrency model.
By this definition, concurrency is only occurring when two things happen simultaneously. coldtea is correct that that is parallelism.
Parallelism, and coldtea's comment does not exclude this, is a special case of concurrency. It is the case where a program's components execute simultaneously. Whereas, generally, concurrency in CS does not require simultaneous action (as you state in your definition).
- millstone 9y agoThat's not the definition I had in mind. What I meant is that JavaScript lacks an easy way to allow for computation that doesn't block the event loop. We can imagine an old school cooperative multithreading architecture: for (var i = 0; i < arr.length; i++) { someCalculation(arr[i]); yieldToNextEvent(); } but JavaScript does not support this. Instead you have to awkwardly re-structure your computation in CPS or an equivalent to do this sort of thing.
- Sacho 9y agoI don't think that's the fault of JavaScript - it does not specify the event loop itself. ES6 has generators, so all you need is an enqueue(fn*(){}). There's already an enqueue in the browser - setTimeout(), and one in node - nextTick(), so all the functionality you need is there.