Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Difference Between Concurrency and Parallelism #31

Open
japananh opened this issue Feb 19, 2024 · 0 comments
Open

The Difference Between Concurrency and Parallelism #31

japananh opened this issue Feb 19, 2024 · 0 comments

Comments

@japananh
Copy link
Owner

japananh commented Feb 19, 2024

The Difference Between Concurrency and Parallelism

Concurrency is a property of the code; parallelism is a property of the running program. - Concurrency in Go
Katherine Cox-Buday

The chunks of our program may appear to be running in parallel, but really they’re executing in a sequential manner faster than is distinguishable. The CPU context switches to share time between different programs, and over a coarse enough granularity of time, the tasks appear to be running in parallel. If we were to run the same binary on a machine with two cores, the program’s chunks might actually be running in parallel.

This reveals a few interesting and important things. The first is that we do not write parallel code, only concurrent code that we hope will be run in parallel. Once again, parallelism is a property of the runtime of our program, not the code.

The second interesting thing is that we see it is possible—maybe even desirable—to be ignorant of whether our concurrent code is actually running in parallel. This is only made possible by the layers of abstraction that lie beneath our program’s model: the concurrency primitives, the program’s runtime, the operating system, the platform the operating system runs on (in the case of hypervisors, containers, and virtual machines), and ultimately the CPUs. These abstractions are what allow us to make the distinction between concurrency and parallelism, and ultimately what give us the power and flexibility to express ourselves. We’ll come back to this.

The third and final interesting thing is that parallelism is a function of time, or context. Remember in “Atomicity” where we discussed the concept of context? There, context was defined as the bounds by which an operation was considered atomic. Here, it’s defined as the bounds by which two or more operations could be considered parallel.

For example, if our context was a space of five seconds, and we ran two operations that each took a second to run, we would consider the operations to have run in parallel. If our context was one second, we would consider the operations to have run sequentially.

@japananh japananh self-assigned this Feb 19, 2024
@japananh japananh changed the title Concurrency vs Parallelism The Difference Between Concurrency and Parallelism Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant