Seqlock
lastmod 2026-11-10created 2020-08-072 edits
Seqlock (sequence lock) is a synchronization technique suited to situations with few writer threads and many reader threads; this page covers a C++ implementation of it. The writer increments a sequence counter, updates the data, and increments the counter again, while a reader copies the data without locking and retries if the counter changed during the read. Because reads never block writes, the approach is also used in the Linux kernel, and getting the memory ordering right is the key to the implementation.
Implementation of Seqlock in C++.