$linuxjunkies
>

atomic operation

also: atomic, atomicity

An operation that completes entirely without interruption, appearing to happen as a single indivisible unit from the perspective of other processes or threads.

An atomic operation is one that cannot be partially completed or interrupted mid-way. Either the entire operation succeeds or it fails cleanly, with no intermediate states visible to other processes. This is critical in concurrent systems where multiple processes or threads access shared resources simultaneously.

Common examples include: a single CPU instruction that updates a register, write() calls of less than PIPE_BUF bytes to a pipe, or a compare-and-swap operation that reads a value, compares it, and writes a new value in one indivisible step. Without atomicity, race conditions can occur where one process sees inconsistent data.

Kernel and library functions like pthread_mutex_lock() provide atomic primitives, and modern CPUs offer atomic instructions (like cmpxchg) that hardware guarantees won't be interrupted by other CPUs. This ensures data consistency in multi-threaded and multi-process applications.

Related terms