<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Atomic on Monoidal Tranformation</title><link>https://monoid.github.io/tags/atomic/</link><description>Recent content in Atomic on Monoidal Tranformation</description><generator>Hugo -- 0.147.2</generator><language>en-us</language><copyright>Copyright © 2025, Ivan Boldyrev; all rights reserved.</copyright><lastBuildDate>Sat, 27 Jun 2026 14:29:28 +0200</lastBuildDate><atom:link href="https://monoid.github.io/tags/atomic/index.xml" rel="self" type="application/rss+xml"/><item><title>False Sharing Alignment</title><link>https://monoid.github.io/posts/false-sharing-alignment/</link><pubDate>Sat, 27 Jun 2026 14:29:28 +0200</pubDate><guid>https://monoid.github.io/posts/false-sharing-alignment/</guid><description>&lt;h1 id="what-is-false-sharing">What is false sharing&lt;/h1>
&lt;p>What is &lt;a href="https://en.wikipedia.org/wiki/False_sharing">false sharing&lt;/a>? When CPUs
and their cores read and update atomic variables, special hardware protocols
make it correct and efficient, while keeping each core&amp;rsquo;s caches consistent. The
coordination doesn&amp;rsquo;t happen per-address: these protocols work on
cache-line-sized chunks.&lt;/p>
&lt;p>What happens when two atomic variables happen to reside on the same cache line?
For example:&lt;/p>
&lt;ul>
&lt;li>an array of atomics where each atomic is used by a separate thread (e.g. per-thread counters);&lt;/li>
&lt;li>a queue with two atomic pointers where a writer updates the tail and a
reader updates the head. Of course, you declare both pointers in the same
struct and they have adjacent addresses!&lt;/li>
&lt;/ul>
&lt;p>Each update operation makes the cache line dirty and requires coordination
between CPUs. The CPUs are essentially playing ping pong with the chunk of
memory.&lt;/p></description></item></channel></rss>