What information entered the process?
Labs / Computer Science
Race Condition Lab
Two threads each try to add 1 to the same counter, over and over. But “add 1” is really three steps — read, increment, write — and when those steps interleave, an update can quietly disappear. Turn on the mutex to fix it, or switch to Manual and click a thread to schedule the steps yourself.
Labs / Computer Science / Race Condition Lab
Race Condition Lab
Two threads each try to add 1 to the same counter, over and over. But “add 1” is really three steps — read, increment, write — and when those steps interleave, an update can quietly disappear. Turn on the mutex to fix it, or switch to Manual and click a thread to schedule the steps yourself.
Why it matters
Why explore this?
Computer science turns clear rules into reliable processes. This model lets you step through those rules and see how each decision changes the result.
Explore
Try the model
Investigate
Questions to test
Predict first, try it in the model, then use what you observe to answer.
What to try
- With no lock, why does the counter almost never reach the expected total, even though every increment “ran”?
- Switch to Manual and interleave the steps by hand: can you make both threads read the same value and then clobber each other on write?
- Turn on the mutex lock. Where do the lost updates go — and what is Thread B doing while it says “waiting for lock”?
- Set one thread very fast and the other very slow. Do collisions happen more often or less often than when both run at equal speed?
- If two threads can lose an update, how many might vanish with ten threads — and is a single shared lock still enough?
Explain
Make sense of what happened
Trace the process one step at a time. Name the rule used at each important step, then explain why the final result follows from those rules.
Check
Before you leave
Which rule changed it?
Why did the process produce this result?
If you can answer all three using evidence from the model, you understand the main idea. If not, return to Explore and change one setting at a time.