Skip to catalogue

192

atomic operation

The update happens entirely or not at all, even when two threads do it. A read-modify-write of a normal variable is not atomic.

What is atomic operation?

An atomic operation is indivisible: increment, compare-and-swap. Two threads incrementing a plain integer can lose updates. Atomics and database atomic updates exist so you do not take a lock for a single counter. They do not make a sequence of several atomics atomic as a group.

Why does atomic operation matter when vibe coding?

Models do `count = count + 1` on shared state and on a database row without `UPDATE SET count = count + 1`. Both lose increments. Name the operation.

How do you do atomic operation?

One atomic increment or a single SQL update. Do not read into the app, add one, and write back unless you have a version check. A group of atomics needs a transaction or a lock.

How do you ask a model for atomic operation?

Make (update) atomic. Use an atomic increment or a single SQL statement. Do not read the value into the app and write it back. Do not assume two atomic lines are one atomic change.

What goes wrong with atomic operation?

Compare-and-swap in a loop with no backoff on a hot counter. You built contention out of atomics. Shard the counter.

adjacent