Back
+15 XP
Concept

Concurrency vs Parallelism: The Core Difference

Concurrency is about *dealing with* many things at once (juggling tasks on one thread during I/O waits). Parallelism is about *doing* many things at once across CPU cores ๐Ÿคน.

python
# Concurrency: 1 chef juggling boiling soup while chopping garlic ๐Ÿคน
# Parallelism: 4 chefs working simultaneously at 4 independent stoves ๐ŸŽ๏ธ

print("Concurrency: Interleaved execution during idle wait times ๐Ÿคน")
print("Parallelism: True simultaneous execution on multiple CPU cores ๐ŸŽ๏ธ")

# 42. Concurrency vs Parallelism: The Core Difference Concurrency is about *dealing with* many things at once (juggling tasks on one thread during I/O waits). Parallelism is about *doing* many things at once across CPU cores ๐Ÿคน. ```python # Concurrency: 1 chef juggling boiling soup while chopping garlic ๐Ÿคน # Parallelism: 4 chefs working simultaneously at 4 independent stoves ๐ŸŽ๏ธ print("Concurrency: Interleaved execution during idle wait times ๐Ÿคน") print("Parallelism: True simultaneous execution on multiple CPU cores ๐ŸŽ๏ธ") ``` A single-core machine can be concurrent by switching tasks rapidly during I/O pauses, but it can never run code in true hardware parallelism! ๐Ÿคน --- ### Question What is the key difference between concurrency and parallelism? ๐Ÿง  - [ ] a. Concurrency interleaves multiple tasks; parallelism executes tasks simultaneously on separate CPU cores ๐Ÿคน - [ ] b. Concurrency is only supported on Linux; parallelism is only supported on Windows - [ ] c. Parallelism requires 0 MB of RAM while concurrency requires 16 GB - [ ] d. Concurrency can only run synchronous print statements --- ### Challenge Write a function `execution_mode(cores)` returning `'Parallel'` if `cores > 1` else `'Concurrent'`. Print `execution_mode(1)` and `execution_mode(8)`. ๐ŸŽฏ <details> <summary>Solution</summary> ```python def execution_mode(cores): return "Parallel" if cores > 1 else "Concurrent" print(execution_mode(1)) print(execution_mode(8)) ``` </details>

Checkpoint

What is the key difference between concurrency and parallelism? ๐Ÿง 

Practice

Write a function `execution_mode(cores)` returning `'Parallel'` if `cores > 1` else `'Concurrent'`. Print `execution_mode(1)` and `execution_mode(8)`. ๐ŸŽฏ

Terminal
01
Tap code blocks below to assemble
Available Blocks