Remove implicit initialization of the global thread pool registry#157017
Remove implicit initialization of the global thread pool registry#157017zetanumbers wants to merge 1 commit into
Conversation
|
r? @mejrs rustbot has assigned @mejrs. Use Why was this reviewer chosen?The reviewer was selected based on:
|
There was a problem hiding this comment.
as a first step.
As a first step towards doing what? Can you provide an overview for this bigger change and/or link/create to a tracking issue for it?
@rustbot author
|
Reminder, once the PR becomes ready for a review, use |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
As a first step towards confidently and safely relying on that assumption. |
There was a problem hiding this comment.
As a first step towards confidently and safely relying on that assumption.
But isn't the threadpool always unique whether it is initialized explicitly or implicitly? Just glancing at the code it looks like it is only ever set once. It looks like the assumption here is really "we always explicitly initialize the threadpool before attempting to use it".
| /// Starts the worker threads (if that has not already happened). If | ||
| /// initialization has not already occurred, use the default | ||
| /// configuration. |
There was a problem hiding this comment.
Please adjust the documentation.
| /// Starts the worker threads (if that has not already happened). If | ||
| /// initialization has not already occurred, use the default | ||
| /// configuration. | ||
| #[cold] |
There was a problem hiding this comment.
| #[cold] |
Isn't this called quite a lot?
| static mut THE_REGISTRY: Option<Arc<Registry>> = None; | ||
| static THE_REGISTRY_SET: Once = Once::new(); |
There was a problem hiding this comment.
It looks like this could just be a OnceLock and global_registry a wrapper around once_lock.get().unwrap(). Thoughts? Is this already part of followup work you are planning?
I think we are regularly relying on the assumption that we are working inside of a unique thread pool. So I think having a panic instead of an implicit thread pool initialization should be a sensible change as a first step towards safely relying on that assumption.
Also with this assumption we should be able to remove registry verification from
WorkerLocal::deref's implementation.cc @Zoxc