<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ks_c_5601-1987">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hi,</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I'd also like to add here that Condition::await() is allowed to return spuriously, leading to a reacquisition, and a subsequent release waiting to be woken again, which would change the order from potentially being "next to run" to becoming "last to run". At
least this is the case as I read the implementation logic.</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div id="Signature" style="color: inherit;">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Cheers,<br>
¡î</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<b><br>
</b></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<b>Viktor Klang</b></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Software Architect, Java Platform Group<br>
Oracle</div>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> core-libs-dev <core-libs-dev-retn@openjdk.org> on behalf of Daniel Fuchs <daniel.fuchs@oracle.com><br>
<b>Sent:</b> Thursday, 5 September 2024 14:11<br>
<b>To:</b> ±è¹ÎÁÖ <miiiinju00@gmail.com><br>
<b>Cc:</b> core-libs-dev@openjdk.org <core-libs-dev@openjdk.org><br>
<b>Subject:</b> Re: [External] : Re: [POTENTIAL BUG] Potential FIFO violation in BlockingQueue under high contention and suggestion for fair mode in ArrayBlockingQueue and LinkedBlockingQueue</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Hi Kim,<br>
<br>
On 05/09/2024 06:10, ±è¹ÎÁÖ wrote:<br>
> If I use an external lock, T1 will block in the |await()| state, but T2, <br>
> T3, and T4 will be waiting for the external lock rather than entering <br>
> the |await()| state in |put()|. This would prevent me from simulating <br>
> the specific behavior I¡¯m trying to test.<br>
<br>
I understand. But my point is that waking up callers in exactly the<br>
same order they have have arrived may not be of much interest since you<br>
would need first to ensure that they arrive in exactly that<br>
proper order.<br>
<br>
> I¡¯d appreciate your thoughts on whether this behavior (where a newly <br>
> arriving thread can overtake a waiting thread) is expected or if it¡¯s <br>
> worth further investigation. As this is my first attempt to contribute <br>
> to OpenJDK, I¡¯m eager to learn from the process and would love to help <br>
> resolve the issue if necessary.<br>
<br>
I am not sure how strong the "fairness" constraint is.<br>
<br>
Typically for monitors, when a thread is signaled after the monitor<br>
is released "it competes in the usual manner with other threads for the <br>
right to synchronize on the object"<br>
<a href="https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/lang/Object.html#wait(long,int)">https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/lang/Object.html#wait(long,int)</a><br>
<br>
That said, we're speakings of locks here - and the only thing I<br>
could find (in ReentrantLock) is that if fairness is set, then<br>
"under contention, locks favor granting access to the<br>
longest-waiting thread", but note that "fairness of locks does<br>
not guarantee fairness of thread scheduling. Thus, one of many<br>
threads using a fair lock may obtain it multiple times in<br>
succession while other active threads are not progressing and<br>
not currently holding the lock."<br>
<a href="https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/util/concurrent/locks/ReentrantLock.html">https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/util/concurrent/locks/ReentrantLock.html</a><br>
<br>
I am not an expert of the java.util.concurrent package, and<br>
hopefully others in this list will be able to provide more<br>
insights.<br>
<br>
> Also, since English is not my first language, I hope my previous emails <br>
> didn¡¯t come across as rude or unclear. If they did, I sincerely <br>
> apologize, as it was never my intention to be disrespectful. I¡¯m still <br>
> learning how to communicate effectively in this space, and I appreciate <br>
> your understanding and patience.<br>
<br>
Hey - you're welcome - and I found your emails quite clear.<br>
But English is not my first language either ;-)<br>
<br>
best regards,<br>
<br>
-- daniel<br>
<br>
> <br>
> Thank you for your time and guidance.<br>
> <br>
> Best regards,<br>
> <br>
<br>
</div>
</span></font></div>
</body>
</html>