Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exit_handler is not run for the global thread pool #483

Open
Yamakaky opened this issue Nov 28, 2017 · 3 comments
Open

exit_handler is not run for the global thread pool #483

Yamakaky opened this issue Nov 28, 2017 · 3 comments

Comments

@Yamakaky
Copy link

If I add in my main:

let rayon_conf = Configuration::new().start_handler(|i| println!("{}", i)).exit_handler(|i| println!("{}", i));
rayon::initialize(rayon_conf).unwrap();

the start_handler is run, but not the exit_handler. It works correctly if I use a ThreadPool.

@cuviper
Copy link
Member

cuviper commented Nov 28, 2017

I think technically, the global thread pool is never stopped. Values in Rust static variables never run their destructors, and only relatively recently supported Drop types at all (RFC 1440). IIRC non-main threads will just terminate immediately when the process exits, so no, they won't run exit_handler.

In fact, I think even ThreadPool's Drop does not synchronously stop threads, just signals for them to "gradually terminate". I think we could add a synchronous terminate method though, if you really need to make sure the exit_handler runs.

@Yamakaky
Copy link
Author

Yeah, that's what I thought.
I need it to run https://docs.rs/flame/0.2.0/flame/fn.commit_thread.html. Flame records timing in a threadlocal struct and adds it to the global store to prevent locking too much. If this function isn't run, I only see the timings for the main lock.

cuviper added a commit to cuviper/rayon that referenced this issue Dec 14, 2017
A broadcast runs the closure on every thread in the pool, then collects
the results.  It's scheduled somewhat like a very soft interrupt -- it
won't preempt a thread's local work, but will run before it goes to
steal from any other threads.

This can be used when you want to precisely split your work per-thread,
or to set or retrieve some thread-local data in the pool, e.g. rayon-rs#483.
@cuviper
Copy link
Member

cuviper commented Dec 14, 2017

If you get a chance to try #492, I think that will work for your commit_thread.

I'm also playing with a way to sync the thread exits, to make sure a given pool is totally done, but I haven't figured out a way to safely shut down the global pool yet.

cuviper added a commit to cuviper/rayon that referenced this issue Oct 3, 2018
A broadcast runs the closure on every thread in the pool, then collects
the results.  It's scheduled somewhat like a very soft interrupt -- it
won't preempt a thread's local work, but will run before it goes to
steal from any other threads.

This can be used when you want to precisely split your work per-thread,
or to set or retrieve some thread-local data in the pool, e.g. rayon-rs#483.
cuviper added a commit to cuviper/rayon that referenced this issue Oct 3, 2018
A broadcast runs the closure on every thread in the pool, then collects
the results.  It's scheduled somewhat like a very soft interrupt -- it
won't preempt a thread's local work, but will run before it goes to
steal from any other threads.

This can be used when you want to precisely split your work per-thread,
or to set or retrieve some thread-local data in the pool, e.g. rayon-rs#483.
cuviper added a commit to cuviper/rayon that referenced this issue Nov 14, 2018
A broadcast runs the closure on every thread in the pool, then collects
the results.  It's scheduled somewhat like a very soft interrupt -- it
won't preempt a thread's local work, but will run before it goes to
steal from any other threads.

This can be used when you want to precisely split your work per-thread,
or to set or retrieve some thread-local data in the pool, e.g. rayon-rs#483.
cuviper added a commit to cuviper/rayon that referenced this issue Apr 24, 2019
A broadcast runs the closure on every thread in the pool, then collects
the results.  It's scheduled somewhat like a very soft interrupt -- it
won't preempt a thread's local work, but will run before it goes to
steal from any other threads.

This can be used when you want to precisely split your work per-thread,
or to set or retrieve some thread-local data in the pool, e.g. rayon-rs#483.
cuviper added a commit to cuviper/rayon that referenced this issue May 9, 2019
A broadcast runs the closure on every thread in the pool, then collects
the results.  It's scheduled somewhat like a very soft interrupt -- it
won't preempt a thread's local work, but will run before it goes to
steal from any other threads.

This can be used when you want to precisely split your work per-thread,
or to set or retrieve some thread-local data in the pool, e.g. rayon-rs#483.
cuviper added a commit to cuviper/rayon that referenced this issue Jun 11, 2022
A broadcast runs the closure on every thread in the pool, then collects
the results.  It's scheduled somewhat like a very soft interrupt -- it
won't preempt a thread's local work, but will run before it goes to
steal from any other threads.

This can be used when you want to precisely split your work per-thread,
or to set or retrieve some thread-local data in the pool, e.g. rayon-rs#483.
cuviper added a commit to cuviper/rayon that referenced this issue Oct 26, 2022
A broadcast runs the closure on every thread in the pool, then collects
the results.  It's scheduled somewhat like a very soft interrupt -- it
won't preempt a thread's local work, but will run before it goes to
steal from any other threads.

This can be used when you want to precisely split your work per-thread,
or to set or retrieve some thread-local data in the pool, e.g. rayon-rs#483.
cuviper added a commit to cuviper/rayon that referenced this issue Nov 16, 2022
A broadcast runs the closure on every thread in the pool, then collects
the results.  It's scheduled somewhat like a very soft interrupt -- it
won't preempt a thread's local work, but will run before it goes to
steal from any other threads.

This can be used when you want to precisely split your work per-thread,
or to set or retrieve some thread-local data in the pool, e.g. rayon-rs#483.
bors bot added a commit that referenced this issue Nov 16, 2022
492: Add ThreadPool::broadcast r=cuviper a=cuviper

A broadcast runs the closure on every thread in the pool, then collects
the results.  It's scheduled somewhat like a very soft interrupt -- it
won't preempt a thread's local work, but will run before it goes to
steal from any other threads.

This can be used when you want to precisely split your work per-thread,
or to set or retrieve some thread-local data in the pool, e.g. #483.

Co-authored-by: Josh Stone <[email protected]>
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

No branches or pull requests

2 participants