SoDeep IconSoDeep
·
how a computer handles race conditions

how a computer handles race conditions

@Nan_Binary · June 25, 2026

Computers brag about doing a billion things at once, but they're terrible at sharing. If two processes try to update the same data at the exact same millisecond, they overwrite each other and cause chaos. That's a race condition.

To stop this digital faff, computers use a crude trick called a "lock." It's just like the latch on a beachside changing hut.

When one process goes in to change data, it bolts the door. The other must wait outside, tapping its foot, until it's unlocked.

What if the door stays bolted forever and nobody can get in?

Oh, you’ve hit on the dreaded 'deadlock,' and it’s as miserable as a rainy day at the pier. This happens when two processes are so stubborn they get stuck in a circular wait. Imagine two people each holding the key to the other’s changing hut; neither can move because they’re both waiting for the other to finish first.

In the computer world, this is a total standoff. The processor just sits there twiddling its thumbs while your software freezes up completely. It’s the digital equivalent of two overly polite neighbors refusing to walk through a narrow gate first until they both eventually starve to death.

To fix this faff, the system usually has to act like a grumpy lifeguard. It blows the whistle, identifies the jam, and forcibly resets one of the processes to break the cycle and get the queue moving again.

Wait, doesn't resetting a process just delete everything it was doing?

It’s a right mess, isn’t it? Just like if I’m halfway through knitting a jumper and drop a stitch so badly I have to unravel the whole sleeve. You lose the progress, but it’s better than having a lumpy mess that never gets finished.

In computer-speak, we call this 'rollback.' The system tries to be clever and save a 'snapshot'—like taking a photo of your jigsaw puzzle before the cat knocks it over—so it doesn't have to start from the very first piece.

But yes, usually, one process has to take the fall. It’s a bit of a sacrifice for the greater good, otherwise the whole computer stays frozen until the sun goes down.

Taking photos of every single move sounds like a massive waste of time, no?

You’re spot on, dear. It’s like trying to cook a roast but stopping to take a Polaroid of every potato you peel. It’s a right performance that drags the whole afternoon out.

This extra work is called "overhead." If the computer took a snapshot every microsecond, it would spend all its time playing photographer and never actually finish the chores.

Programmers have to be picky, only taking a "photo" at important milestones. That way, if the cat knocks the tray over, you only lose the gravy, not the whole meal.

Is there a rule for which moments are actually 'important'?

Not a hard rule, dear, but they look for 'logical boundaries.' It’s like waiting for a natural pause in a conversation before you interrupt for a photo without making a right faff of it.

If they snapshot in the middle of a complex sum, it’s like trying to pause a sneeze—it’s messy and simply won't work. They need a moment where the data is 'clean' and sitting still.

It’s mostly experience. They imagine the worst-case scenario and tuck a safety net just before the most wobbly part of the tightrope walk.

Explore in card mode →

Related topics

The way 'data redundancy' prevents information from being lostThe way 'latency' causes a delay in your digital communicationThe way 'sandboxing' isolates suspicious computer programsThe way a computer compiler translates code into machine instructionsHow a computer uses 'queues' to handle information in orderThe logic of 'database indexing' for finding information quickly