Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions core/src/main/java/io/netty/loom/EventLoopScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,16 @@ private static ThreadFactory newEventLoopSchedulerFactory(SharedRef sharedRef) {
// and share it between the thread attachment and the SchedulingContext,
// enabling
// work-stealing to change it for both
return runnable -> NettyScheduler.newEventLoopScheduledThread(() -> ScopedValue
.where(CURRENT_SCHEDULER, new SchedulingContext(Thread.currentThread().threadId(), sharedRef))
.run(runnable), sharedRef);
var unstartedBuilder = Thread.ofVirtual();
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlanBateman I would have expected this new method to be static in Thread.OfVirtual.

Second: do you think is ok to make users able to set the preferred carrier?
e.g. see the comment below

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you asking why the 3-arg unstarted method is an instance method then it needs to be in order to pick up other properties set via other builder methods. The overload is a restricted method in the prototype to deter casual use.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for answering Alan!
And in relation to setting the preferred carrier instead: do we really want users to be able to do that?
I would have expected this argument to be useful for pollers - whilst users which implement their custom scheduler could enforce it by other means e.g. like I am doing in the Netty scheduler, dynamically

// we're not enforcing a preferred carrier on purpose, despite we could - to prevent leaks to happen:
// once this scheduler is gone, but a virtual thread is still to complete, we would like to offload it
// to the default scheduler rather than trying to reuse this scheduler's carrier thread
return runnable -> unstartedBuilder.unstarted(() -> runWithContext(runnable, sharedRef), null, sharedRef);
}

private static void runWithContext(Runnable runnable, SharedRef sharedRef) {
ScopedValue.where(CURRENT_SCHEDULER, new SchedulingContext(Thread.currentThread().threadId(), sharedRef))
.run(runnable);
}

int externalContinuationsCount() {
Expand Down
4 changes: 0 additions & 4 deletions core/src/main/java/io/netty/loom/NettyScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,6 @@ public void onContinue(Thread.VirtualThreadTask virtualThreadTask) {
jdkBuildinScheduler.onContinue(virtualThreadTask);
}

static Thread newEventLoopScheduledThread(Runnable task, SharedRef sharedRef) {
return Thread.VirtualThreadScheduler.newThread(task, sharedRef);
}

public static boolean perCarrierPollers() {
return ensureInstalled().perCarrierPollers;
}
Expand Down
Loading