pub unsafe extern "C" fn dr_register_thread_exit_event(
func: Option<unsafe extern "C" fn(drcontext: *mut c_void)>,
)Expand description
Registers a callback function for the thread exit event. DR calls \p func whenever an application thread exits. The passed-in drcontext should be used instead of calling dr_get_current_drcontext(), as the thread exit event may be invoked from other threads, and using dr_get_current_drcontext() can result in failure to clean up the right resources, and at process exit time it may return NULL.
On Linux, SYS_execve may or may not result in a thread exit event. If the client registers its thread exit callback as a pre-SYS_execve callback as well, it must ensure that the callback acts as noop if called for the second time.
On Linux, the thread exit event may be invoked twice for the same thread if that thread is alive during a process fork, but doesn’t call the fork itself. The first time the event callback is executed from the fork child immediately after the fork, the second time it is executed during the regular thread exit. Clients may want to avoid touching resources shared between processes, like files, from the post-fork execution of the callback. The post-fork version of the callback can be recognized by dr_get_process_id() returning a different value than dr_get_process_id_from_drcontext().
See dr_set_process_exit_behavior() for options controlling performance and whether thread exit events are invoked at process exit time in release build.