Remove the per-Bus unparking thread - #42
Open
updawg wants to merge 1 commit into
Open
Conversation
Bus::new spawns a thread whose only job is to call unpark() so that broadcast_inner doesn't have to. Its JoinHandle is dropped, so the thread lives for the whole life of the Bus and can never be joined. Unpark inline in broadcast_inner instead and drop the thread. That puts the unpark back on the broadcast path (only when there's a blocked receiver to wake), but a Bus no longer holds a background thread it can't clean up.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bus::newspawns a dedicated thread whose only job is to callunpark()so thatbroadcast_innerdoesn't have to. The handle is dropped, so that thread runs for the entire lifetime of theBusand there's no way to join it.That means every
Buspermanently owns a background thread. In a process that creates a lot of buses, or in tests that assert no threads are leaked, the lingering thread is awkward to account for.This drops the thread and calls
unpark()inline inbroadcast_inneragain. The trade-off is that the unpark is back on the broadcast path (only when there's actually a blocked receiver to wake) — the cost the thread was added to hide. For my use that's the better trade, but if you'd rather keep the optimization I'm happy to put it behind a feature flag or join the thread inDropinstead.Existing tests pass.