Skip to content

Use a single synchronized block in Dispatcher#9110

Merged
swankjesse merged 1 commit into
masterfrom
jwilson.1006.single_synch
Oct 6, 2025
Merged

Use a single synchronized block in Dispatcher#9110
swankjesse merged 1 commit into
masterfrom
jwilson.1006.single_synch

Conversation

@swankjesse

Copy link
Copy Markdown
Collaborator

Previously we had synchronized blocks preceding calls to promoteAndExecute, plus the synchronized blocks in that function itself.

This is intended to make it easier to publishg the right events for dispatcherQueueStart and dispatcherQueueEnd when an enqueued call can skip the queue.

Also note that this should fix some corner-cases around unnecessary calls to idleCallback when the executor is already shut down.

Previously we had synchronized blocks preceding calls
to promoteAndExecute, plus the synchronized blocks in
that function itself.

This is intended to make it easier to publishg the right
events for dispatcherQueueStart and dispatcherQueueEnd
when an enqueued call can skip the queue.

Also note that this should fix some corner-cases around
unnecessary calls to idleCallback when the executor is
already shut down.

asyncCall.failRejected()
}
idleCallback?.run()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I believe this would have triggered unnecessary calls to the idle callback. For example, each time maxRequests is mutated, this would be called if the executor service was shut down, even if it was already idle.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice catch

@yschimke yschimke left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It's a tough review, but I think our tests and lock checks make this safe. We should pay attention to flakes

while (i.hasNext()) {
val asyncCall = i.next()
// Actions to take outside the synchronized block.
class Effects(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I like this pattern across barriers

@swankjesse swankjesse merged commit e3e9960 into master Oct 6, 2025
29 checks passed
@swankjesse swankjesse deleted the jwilson.1006.single_synch branch October 6, 2025 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants