Middle+
What problems do you know related to parallelization?
sobes.tech AI
Answer from AI
- Race condition: Multiple threads/processes access and modify shared data simultaneously, leading to unpredictable results.
- Deadlock: Two or more threads wait for resources held by each other, causing the system to hang.
- Starvation: A low-priority thread does not get access to resources, waiting indefinitely.
- Synchronization overhead: Using locks and other synchronization primitives requires time and resources, reducing overall performance.
- Debugging complexity: Debugging parallel code is difficult due to the unpredictable order of thread execution and the difficulty of reproducing problems.
- Non-determinism: The program's execution result can vary each run due to different thread execution orders.
- Scalability: Inability to scale performance proportionally to the number of cores due to limitations in the algorithm or architecture.
- False sharing: Multiple threads access different data located in the same cache line, causing constant cache invalidation.
Example of Race condition:
class Counter {
private int count = 0;
public void increment() {
count++;
}
public int getCount() {
return count;
}
}
// If two threads call increment simultaneously without synchronization,
// the final value of count may be less than expected.