<p dir="auto">One of my coworkers made the following observation:</p>
<blockquote>
<p dir="auto">I noticed the julia profiler is sampling all the threads in a deterministic order, which can skew the profile for multithreaded code.  When you stop one thread holding an important mutex, you can get a pileup of threads blocking for that mutex, which can make it seem like there's lots of mutex contention, but really that mutex contention is caused by the profiler.</p>
</blockquote>
<p dir="auto">We talked about this with <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/JeffBezanson/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/JeffBezanson">@JeffBezanson</a> last month, and I'm opening an issue about this so we don't forget. :)<br>
We guessed probably the best thing to do is to select one thread at random and record a sample for just that thread? But it'd be best to consult an expert on multithreaded profiling.</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; sort(unsigned.([1,0,1,0,1,1]), rev=true)
6-element Vector{UInt64}:
 0x0000000000000001
 0x0000000000000000
 0x0000000000000001
 0x0000000000000000
 0x0000000000000001
 0x0000000000000001"><pre class="notranslate">julia<span class="pl-k">&gt;</span> <span class="pl-c1">sort</span>(<span class="pl-c1">unsigned</span>.([<span class="pl-c1">1</span>,<span class="pl-c1">0</span>,<span class="pl-c1">1</span>,<span class="pl-c1">0</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span>]), rev<span class="pl-k">=</span><span class="pl-c1">true</span>)
<span class="pl-c1">6</span><span class="pl-k">-</span>element Vector{UInt64}<span class="pl-k">:</span>
 <span class="pl-c1">0x0000000000000001</span>
 <span class="pl-c1">0x0000000000000000</span>
 <span class="pl-c1">0x0000000000000001</span>
 <span class="pl-c1">0x0000000000000000</span>
 <span class="pl-c1">0x0000000000000001</span>
 <span class="pl-c1">0x0000000000000001</span></pre></div>
<p dir="auto">see <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="1031507047" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/42718" data-hovercard-type="pull_request" data-hovercard-url="/JuliaLang/julia/pull/42718/hovercard" href="https://github.com/JuliaLang/julia/pull/42718">#42718</a> for why this bug exists</p>