Availability:C-language interface function
int PL_thread_at_exit(void 
(*function)(void *), void *closure, int global)Register a handle to be called as the Prolog engine is destroyed. The 
handler function is called with one void * argument holding
closure. If global is TRUE, the 
handler is installed
for all threads. Globally installed handlers are executed after 
the thread-local handlers. If the handler is installed local for the 
current thread only (global == FALSE) it is 
stored in the same FIFO queue as used by thread_at_exit/1.