
cowwoc wrote:
Unless I missed something, I don't think that the scenario you propose would work for my use-case. Basically, I've got a thread that runs in an endless loop until the program shuts down. When the program shuts down, I want it to clean up some resources cleanly. The way I've done this is by registering a at_thread_exit() hook that causes the aforementioned thread to shut down cleanly (breaking out of the endless loop) thereby allowing it to clean up its resources cleanly.
You can't use an at_thread_exit hook registered from within a thread to shut down this same thread; this is circular. If you want to shut down a thread when exit() is called or when main returns, use atexit, or a destructor of a static variable. I don't see how at_thread_exit could help in this case, although of course I may be misunderstanding something.