On Tue, 6 Dec 2022 10:16:38 GMT, Alan Bateman <[email protected]> wrote:

> The implementation of Thread.yield for virtual threads is currently a "lazy 
> submit". This means the task for the virtual thread is queued to the 
> carrier/worker local queue without signalling other threads. This behavior 
> can be surprising/unfair when there are tasks in the submission queues, say 
> when a platform thread has started or unparked a virtual thread.
> 
> Ron, Doug Lea, Viktor Klang and I have discussed this topic and propose to 
> change Thread.yield to  use "external submit" when the local task queue is 
> empty, and to push to the local queue when not empty. The change improves the 
> fairness but will of course increase the chances that repeated Thread.yield 
> will bounce between carriers.

I'm not too familiar with the local queue and submission queues of the 
ForkJoinPool, but the PR description and the inline comments in the code/tests 
helped understand this change. With my limited knowledge of this area, this 
change looks OK to me.

I'm guessing the change to the existing `YieldALot` test to reduce the number 
of iterations from `500000` to `350000` is intentional to bring down the 
duration of that test?

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

Marked as reviewed by jpai (Reviewer).

PR: https://git.openjdk.org/jdk/pull/11533

Reply via email to