3 ms·
Understanding Memory Reordering
- ncmncm 7y agoWhenever you read "lock-free", think "locking in microcode". These atomic operations trigger hardware state machines that work remarkably similarly, in character, to what happens for a lock, and are often little faster. But they are quite a lot harder to get right. If you think you need lock-free, usually what you really need is less contention, or a single-writer ring buffer. Sometimes lock-free is right, and sometimes locking is right. But it can be worth quite a lot to find a way not to need either one.