Issues & Challenges#
Indeterminacy: Outcomes depend on the timing of events.
Execution Risks: Incorrect outcomes, deadlocks, or process starvation.
The Efficiency Gap: Concurrency is only potential for efficiency.
Engineering Challenges:
Reliable coordination of execution.
Safe data exchange and memory allocation.
Mitigating communication overhead.
Implementing overlapped operations requires:
Resource contention: Shared network buffers or bandwidth limits.
Memory management: Risk of overuse.
Indeterminate error handling: Timing of failure detection altering program flow.
Coordination overhead: Signaling mechanisms (locks, semaphores).
Example:
The non-atomic increment: counter = counter + 1 requires three steps: Read, Add, Write.
import threading
counter = 0
def increment():
global counter
for _ in range(100000):
counter = counter + 1 # Read, add, write
t1 = threading.Thread(target=increment)
t2 = threading.Thread(target=increment)
t1.start(); t2.start()
t1.join(); t2.join()
print(counter) # Expected: 200000, Actual: Indeterminate
Key Takeaway
The gap between conceptual simplicity and implementation complexity is characteristic of concurrent programming, requiring expertise in synchronization, resource management, and error handling.