3 ms·
Don't atomic operations trigger cache synchronisation in CPUs? Doesn't that affect performance negatively? That would mean even a non-contended mutex would affe
by yakubin 4y ago
Don't atomic operations trigger cache synchronisation in CPUs? Doesn't that affect performance negatively? That would mean even a non-contended mutex would affect performance negatively. I suspect it depends a lot on the specific workload (and maybe even what addresses data is stored at in memory), so I'd measure the specific case, but that's my a priori gut feeling.
- loeg 4y agoIf it's non-contended, the mutex's cache line probably stays Exclusive in the local CPU and acquiring is pretty cheap.
- staticassertion 4y agoIf there's no contention there's no more synchronization compared to any other cache lines afaik.
- rightbyte 4y agoAtamic operations have some overhead.
- staticassertion 4y agoThe overhead of atomics is almost (if not entirely?) exclusively with regards to managing the caches in the CPU. Otherwise they're just normal bytes. Your CPU already has to do some cache management with regular bytes, so an atomic is only worse if there's contention (because that forces a flush). The worst case for an atomic write is two additional cache line flushes, iirc.