seegongsik
Saved words
Operating systems

When two fix the same thing at once

Two fixing the same thing at once can break the result. One at a time is the answer.

01

When two fix the same box

A note with a number is stuck on the wall. It says 10 now. Two people each want to add 1 to it.
One reads 10, makes 11 in their head, and writes 11 on the note. The other does the same. But if they start at nearly the same moment, both read the original 10 and both write 11.
Adding 1 twice should give 12, but the result is 11. One add vanished. It is an accident from fixing the same thing at the same moment.

10ABread 10read 10111111write 11write 11should be 12 but 11one add lost

When two fix the same value at once, one of the adds disappears

Fixing the same thing at the same moment can throw the result off.

02

Same action, different result

The same two people each add 1 the same way, but let us change only the timing.
In turn: one reads 10, writes 11, and finishes, then the other reads that 11 and writes 12. Result 12, correct.
Overlapping: one reads 10 and before writing yet, the other also reads the 10. Both write 11 and the result is 11, wrong.
The actions were literally the same. Only when someone cut in, that one piece of timing, decided right from wrong.

In turnA read10B read11write11write1212rightOverlappingA read10B read1011wrong

The same adding is right done in turn, wrong when overlapped

What decided the result was not the action but the timing of when someone cut in.

03

Overlap them yourself

Two workers each add 1 to the same value. Adjust how much they start overlapping.
Spread them far enough and one finishes before the other starts, so the result is right. Bring them close and one reads before the other writes, so an add vanishes.
Move the slider and see from what point the result breaks. The same two actions, yet the moment they overlap the result collapses.

readchangewriteAreadchangewriteB
12Result right
Overlap20%
Spread apart it is right at 12, overlapped it breaks to 11. Find from what point it turns red.

Change the amount of overlap and see when the result breaks

Spreading them apart keeps the result right, and the more they overlap the higher the risk it breaks.

04

If they take turns one at a time

So how do we prevent it. The answer is simple. While the same thing is being fixed, let only one person touch it.
While one reads, changes, and writes, the others wait. That one bundle must finish before the next starts. Like lining up for a single restroom. If someone is inside, the door locks, and the next goes in only after they come out.
This way there is no overlap, so the result is always right. The cost is some waiting. For safety, you accept a short line.

12Ain useBwaitingone at a time, no overlapbut some waiting

While the same thing is being fixed, only one touches it and the rest line up

Letting one fix the same thing at a time removes overlap and makes the result safe.

05

Put it on one page

Just remember three things.
First, fixing the same thing at the same moment causes accidents. As two adding at once lose one add, the result can go wrong.
Second, the problem is timing, not the action. The same work is right in turn, wrong when overlapped. Third, letting one go at a time is safe. While the same thing is fixed, only one touches it and the rest line up, so the result is always right.

One
Fixing the same thing at the same moment causes accidents. Two adding at once lose one add.
Two
The problem is timing, not the action. Right in turn, wrong when overlapped.
Three
One at a time is safe. Only one touches it while the rest line up, so the result is always right.

At-once plus shared is an accident, timing is the problem, one at a time is safe

In one lineFixing the same thing at once can break the result, and letting one go at a time can prevent it.
Was this helpful? Support seegongsik
Operating systems