[concurrency-interest] On park and unpark

Andrew Haley aph at redhat.com
Fri Aug 25 12:53:57 EDT 2017


On 25/08/17 17:49, Nathan and Ila Reynolds wrote:
> Several years ago, I saw Linux futex perform poorly in the kernel.  
> Futex was getting a bad rap by others as well.  In my experience, the 
> kernel would spend a lot of CPU time dealing with futexes.  I do not 
> remember the circumstances that cause this scenario.  So, I recommend 
> proceeding with caution and lots of testing.  Perhaps, this caution is 
> not warranted and the problem was fixed in the kernel.

That's won't help, because Linux mutexes always use futex.  There's
no way to bypass a futex call if you block.

> For the blocking case, I would guess there would not be much difference 
> in performance.
> 
> I recommend running some microbenchmark tests for the non-blocking case 
> (i.e. unpark() before park()).  You might see a CPU performance gain.

Really?  I doubt it, because the park permit flag would be set so the
park() return immediately.  The only time that wouldn't happen is a
narrow race condition between that flag being tested and a mutex being
acquired.

-- 
Andrew Haley
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671


More information about the Concurrency-interest mailing list