Open Yamakaky opened 6 years ago
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.
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.
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.
If I add in my main:
the start_handler is run, but not the exit_handler. It works correctly if I use a ThreadPool.