Questions: The Critical Section Problem and Race Conditions

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

Two threads each increment a shared counter 1,000,000 times starting from 0. After both threads finish, the final value is 1,756,432 instead of 2,000,000. What is the most likely explanation?

AThe CPU made arithmetic errors on some additions
BA race condition occurred: the load-modify-store sequence is not atomic, so some increments from one thread overwrote increments from the other
CThe threads ran sequentially, so only one completed its full million iterations
DInteger overflow caused some counts to wrap around
Question 2 Multiple Choice

A C++ programmer declares a shared counter as volatile to fix a race condition between two threads incrementing it. Will this solve the problem?

AYes — volatile forces all reads and writes to go directly to memory, preventing stale values
BYes — volatile makes operations on the variable atomic
CNo — volatile only prevents the compiler from caching the variable in a register; it does not make the load-modify-store sequence atomic
DNo — volatile makes the problem worse by disabling all compiler optimizations
Question 3 True / False

A correct solution to the Critical Section Problem must guarantee mutual exclusion, progress, and bounded waiting — satisfying just two of the three is insufficient.

TTrue
FFalse
Question 4 True / False

Race conditions are easy to detect in testing because they generally produce a clearly wrong result or cause the program to crash.

TTrue
FFalse
Question 5 Short Answer

Why does declaring a variable as volatile in C/C++ not fix a race condition on a shared counter?

Think about your answer, then reveal below.