Why does DECR count as atomic but GET then SET does not?
DSA Lesson 4
Real lessons in the time it takes to finish a coffee.
A flash sale drops stock by one. Which command keeps the decrement atomic?
DSA · Lesson 4 · Code analysis
Correct +40 XP
Every course is a run of short lessons. Finish one and the next opens. You can jump ahead, but only by passing a check first, so nothing gets skipped by accident.
Big-O without the notation
What time and space really cost, and why it follows you
Stacks, queues and hash tables
The structures every interview leans on
Daily streaks, XP for every answer, and a weekly league of thirty learners. Finish in the top ten and you move up a tier, from Bronze all the way to Diamond.
See the live leaderboardBronze
Every legend starts here
Tier 1 / 5
Every lesson has a thread. Ask a question, read the explanation someone else already worked out, or leave the shortcut you wish you had found first.
Browse the communityWhy does DECR count as atomic but GET then SET does not?
DSA Lesson 4
GET then SET is two separate steps, so another client can write in between and its value is lost. DECR is a single read-modify-write, so nothing can interleave.
Longer reads from the people writing the courses: roadmaps, worked examples, and the revision order that actually helps.
One lesson. Four minutes. Then you will know whether this works for you.
Start
Read the full post, then sign in free to like and reply.
Loading post…