<div dir="auto">I think it is not about performance, but language support of correctness.<div dir="auto"><br></div><div dir="auto">So to speak, the language provides statements to build programs that are obviously sequentially consistent. (With the caveat that deadlocks probably are evidence of the execution that is not sequentially consistent) </div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 4 Jun 2024, 09:06 Andrew Haley, <<a href="mailto:aph-open@littlepinkcloud.com">aph-open@littlepinkcloud.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 6/3/24 21:09, Cay Horstmann wrote:<br>
<br>
> And why make the lock be "this" so it leaks to the public? Per<br>
> Brinch Hansen wasn't amused: "It is astonishing to me that Java 's<br>
> insecure parallelism is taken seriously by the programming<br>
> community, a quarter of a century after the invention of monitors<br>
> and Concurrent Pascal. It has no merit."<br>
<br>
Oh, I'd never seen that comment! Thanks for the reference.<br>
<br>
> Nothing wrong with an expert using synchronized because it performs<br>
> better. But that begs the question. Why does it perform better?<br>
> Objects typed as locks are surely more suitable as locks than any<br>
> old object. Their performance should be on par with intrinsic locks.<br>
<br>
It's an interesting question. I think the real answer to that is<br>
because java.util.concurrent locks are a pure library feature. The<br>
virtual machine doesn't know anything about their properties so can't,<br>
for example, do lock coarsening. But in principle, sure, the same<br>
optimizations could be done. However, there would always have to be<br>
a link from an object to its lock, which is a small overhead.<br>
<br>
-- <br>
Andrew Haley (he/him)<br>
Java Platform Lead Engineer<br>
Red Hat UK Ltd. <<a href="https://www.redhat.com" rel="noreferrer noreferrer" target="_blank">https://www.redhat.com</a>><br>
<a href="https://keybase.io/andrewhaley" rel="noreferrer noreferrer" target="_blank">https://keybase.io/andrewhaley</a><br>
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671<br>
<br>
</blockquote></div>