On Tue, 13 May 2025 12:34:38 GMT, Chen Liang <li...@openjdk.org> wrote:

>> In the JavaDoc of LinkedBlockingDeque, it states: "Linked nodes are 
>> dynamically created upon each insertion unless this would bring the deque 
>> above capacity." However, in the current implementation, nodes are always 
>> created, even if the deque is full. This is because count is non-volatile, 
>> and we only check inside the linkFirst/Last() methods whether the queue is 
>> full. At this point we have already locked and have created the Node. 
>> Instead, the count could be volatile, and we could check before locking.
>> 
>> In the current version, calling offer() on a full LinkedBlockingDeque 
>> creates unnecessary objects and contention. Similarly for poll() and peek(), 
>> we could exit prior to locking by checking the count field.
>> 
>> Our suggestion is to make count volatile, and then exiting early from poll() 
>> and offer()
>
> @viktorklang-ora Is it possible for you to take a look at this?

@liach This PR should be closed, it's superseded by 
https://github.com/openjdk/jdk/pull/24925

-------------

PR Comment: https://git.openjdk.org/jdk/pull/24521#issuecomment-2876363296

Reply via email to