Wk4L2 - Race Conditions and Barriers Flashcards

1
Q

What is a Race Condition?

A

A race condition occurs when the timing or order of thread execution affects the correctness of the result, even when mutual exclusion is used to prevent concurrent writes to shared resources.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How is a Race Condition different from a Data Race?

A

A data race happens when multiple threads write to the same memory location without proper synchronization, potentially causing data loss. A race condition, however, arises from the order or timing of execution affecting the outcome, even if mutual exclusion is in place.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a real-world analogy for a Race Condition?

A

Imagine agreeing to meet a friend at Tim Hortons on campus, but there are multiple locations. The outcome depends on the order you check the locations and how long you wait. Similarly, in programming, race conditions depend on the execution order of threads.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a Barrier in multithreading?

A

A barrier is a synchronization point where multiple threads stop and wait for each other before continuing execution. Unlike a join, threads do not terminate; they just pause until all threads have reached the barrier.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a CyclicBarrier in Java?

A

A CyclicBarrier is a reusable barrier that waits for a set number of threads (called parties) to reach the barrier before allowing them to proceed. After the barrier is crossed, it can be reused for the next step.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

When are Barriers typically used?

A

Barriers are often used in simulations where threads complete steps in parallel. Each thread finishes a step, waits at the barrier for other threads to complete the same step, and then moves on to the next step.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly