63 comments

criddell6 days ago
This review seems to equate parallelism and concurrency as the same thing and they are not.

As I understand it, the parallelism is about task execution and concurrency is about task structure. Or, as Rob Pike said:

"Concurrency is about dealing with lots of things at once. Parallelism is about doing lots of things at once."

He said that in his Concurrency is not Parallelism talk.

Jtsummers6 days ago
That's a useful interpretation of the two terms, but it's far from universal and the two have often been used fairly interchangeably over the decades. It's been much more useful as a distinction when someone discussing it announces that that is how they're separating the two concepts, instead of trying to force other people to adopt that particular pair of definitions.
miki1232116 days ago
You can have parallelism without much concurrency. Think parsing a bunch of files, where you have a `fn parse(path) -> AST` which does not rely on global state. Parallelizing something like this is trivial, with no mutexes in sight, and can be great for performance in many situations.

On the other hand, you can have concurrency without parallelism. Think a database where IO is the bottleneck, and you have multiple clients doing reading and writing at all once, potentially to the same table, in isolated transactions, on different db nodes which have to communicate. That's a lot of concurrency and nasty locks, even if you're running on a single core and wouldn't get much of a speedup from doing otherwise.

packetlost6 days ago
Frankly the software industry suffers heavily from a lack in standardized terminology. The precise definition of parallelism vs concurrency is one that I think is incredibly important. You are doing your peers a disservice by using them interchangeably, they are not.
ahelwer6 days ago
That battle has unfortunately been lost and different sources give different definitions, often exactly swapped. This was discussed in one of the HN posts linked in the article: https://news.ycombinator.com/item?id=36318280

In the end I don't think it is too much of an issue. What confusion is really brought by conflating parallelism and concurrency? Sure, concurrent programs can be serialized onto a single core (that's how deterministic simulation testing implementations like Antithesis and record & replay implementations like Mozilla's rr operate). But there isn't some deep conceptual unlock you get by having a strict conceptual boundary between concurrency and parallelism.

Athas6 days ago
I think there is a deep conceptual unlock: concurrency is about semantics, whilst parallelism is an operational property. I use this distinction a lot in my own work. Concurrent programming primitives are inherently non-deterministic (and usually about handling non-deterministic events), on top of which we must then establish some kind of properties (sometimes determinism to some extent). Many interesting parallel operations are however completely deterministic, and the fact that they are parallel is a property of their assigned cost model (and hopefully implementation, in practice).

I agree that this distinction is hardly universal, but it seems to be growing increasingly established, and I think it is worth fighting for it.

Dylan168076 days ago
It's really important to get people to recognize that concurrency can happen on a single core or a single task-switching thread. You don't necessarily need to split off parallelism to explain that, but it helps.

And it's worth talking about how you can have a single task run in a parallel way, for varying strictness of 'single'.

Coroutines and SIMD are far enough apart that their execution models should have different words.

jerf6 days ago
Personally I think it's not a good idea to think too rigidly about and try to draw a huge distinction between the two. They're on a continuum and sometimes I'd say some things aren't even strictly speaking "between" them either. Sitting down and trying to classify code into "parallel" and "concurrent" is as likely to do harm as to do any good.
adrian_b6 days ago
The 2 terms have been used inconsistently in the past and some authors have even alternated between them during their lifetime.

I prefer the view where "concurrent" processes (a.k.a. tasks a.k.a. threads) are those where the execution of their parts is done in an unpredictable order, i.e. they can be interleaved in an unpredictable order.

For the correctness of programs, it only matters whether some things are executed sequentially or concurrently. If they are executed concurrently, whichever order of execution happens must not change the results in any way.

For correctness, it does not matter whether in reality all the concurrent processes are executed by a single hardware thread, so none of them are ever executed simultaneously in time, or all the processes are executed in parallel, on different processor cores.

For correct concurrent programming, what matters is how the access to shared resources is controlled, using either mutual exclusion, or optimistic accesses with retries when necessary, or dynamic partitioning of the shared resource (i.e. of an array or of a queue) into disjoint parts that allow concurrent accesses.

Parallelism only matters for the achievable performance of a program. To enable parallel execution for increased performance, there are also specific programming techniques that are required, for minimizing the dependencies that force serial execution, i.e. data dependencies a.k.a. functional dependencies, flow-of-control dependencies and resource dependencies a.k.a. operational dependencies.

Something that can cause confusions between concurrency and parallelism is the difference between the program written by the programmer and how it is really executed by a modern CPU.

When the programmer writes a program that describes multiple concurrent processes, a CPU may easily execute all of them in parallel. But even when the programmer writes only a sequential program, a modern CPU with out-of-order execution will analyze the program, identify the dependencies between instructions and convert the sequential program into a set of concurrent processes that will be executed in parallel by separate hardware execution units, if possible, though they may also be executed sequentially on a single execution unit, when the others are busy.

Thus even when the programmer does not write a concurrent program, it may still have parts that are executed in parallel, but that is not parallelism without concurrency, the concurrency is introduced by the hardware scheduler, which identifies shared resources and any other dependencies that could inhibit the transformation of the sequential program into a concurrent program.

mkehrt6 days ago
As other comments have pointed out, this is just not true in general usage.

When I was a grad student studying this stuff (~20 years ago), we used "parallelism" to mean running on different cores at the same time and "concurrency" to mean preemptive multithreading on a single processor.

wiml6 days ago
That's the same distinction, made in the same way, isn't it?
threethirtytwo6 days ago
Yeah although they say something like nodejs is not parallel but concurrent it’s not technically true from a systems standpoint. There are actually tons of operations happening at the same time. It’s just all delegated to IO.

True concurrency that is absolutely absent of parallelism is a bit pointless, that’s why although node is concurrent, it is explicitly designed such that it migrates parallelism to IO.

gpderetta6 days ago
> True concurrency that is absolutely absent of parallelism is a bit pointless

It is very important in interactive or realtime systems.

bolangi6 days ago
The Raku language (formerly Perl 6) and its underlying VM has features to support parallel programming, concurrency and asynchrony, designed to make common cases relatively easy to code and avoid pitfalls.

Jonathan Worthington, the author of the VM and these features, has given an excellent presentation on the concepts and their implementation.

https://www.youtube.com/watch?v=JpqnNCx7wVY

raffraffraff5 days ago
TIL they renamed Perl 6!
anonymousDan6 days ago
I would probably recommend the art of multiprocessor programming (herlihy and shavitz) as a good starting point for concurrent programming. There is also " A primer on memory consistency and cache coherence" (Nagarajan et al) if you want to get more into the interaction between memory consistency and coherence.
RossBencina6 days ago
I can recommend "Shared Memory Synchronization," by Michael L. Scott for an introduction to nuts-and-bolts level detail.
cbm-vic-206 days ago
Should have been titled "Is Parallel Programming What Can You Hard, And, If So, Do About It?"
nnevatie6 days ago
The plural of a mutex is "deadlock"
crooked-v6 days ago
Don't dead, open inside.
ozarkerD6 days ago
world! hello
igsomething6 days ago
I do agree with your comment.

not not

hoistway6 days ago
Spent days tracking down a deadlock that only manifested under specific load. Definitely hard, even with good tooling.
kccqzy6 days ago
What kind of tooling were you using? IMO, deadlocks are some of the easiest concurrency bugs to diagnose. If you can see the thread stacks, it is easy to see threads are blocked from acquiring a lock. If you can attach a debugger, it is easy to see which locks are involved. Then you can pretty much figure things out using the straightforward guideline that if multiple locks are involved, they must be acquired in the same order in all code paths.

I don't want to devalue your experience, but I am surprised to hear that. Livelock is harder to debug. Silent data corruption caused by missing or wrong synchronization is way harder to debug.

gpderetta6 days ago
Agree completely. But they become harder when you eschew standard constructs like threads and mutexes and bring-your-own losing nice things like debugger supports and stack traces. Now your logical tasks might be deadlocked, while your threads appear to be running correctly. This is surprisingly common this day with async runtimes and less than stellar debugging support.
stingraycharles6 days ago
> Silent data corruption caused by missing or wrong synchronization is way harder to debug.

Reminds me of being a young and ambitious C++ programmer 25 years ago, discovering that when you have a map and do “return m[k]”, it is not, in fact, a read-only operation when k does not exist. After which I learned that const-correctness is not just a nice-to-have, especially in multithreaded applications.

But yeah deadlocks are hardly ever a difficult issue to diagnose. They may potentially be difficult to resolve, but at that point, it very much suggests that there’s an architecture / design issue.

afdbcreid6 days ago
They are, if you can attach a debugger. If only one thread is stuck and in production... Not so much (but there are still much harder bugs).

Read the full thread on Hacker News →

Related stories