APR thread cleanup is explained in decent detail in the threading section of the APR Tutorial. In order, the cleanup steps look like this:
- Call
apr_thread_exit()
in the thread itself. While Unix threads terminate automatically, Windows threads do not. Call this function for portability (and to a return a status, if necessary). - Call
apr_thread_join()
in the main thread to wait for the termination of all threads. - Call
apr_pool_destroy()
to free the main memory pool. (Child memory pools are freed withapr_thread_exit()
.) - Call
apr_terminate()
to release other resources (sockets, etc.). Note that simply callingexit()
in another thread without these final steps can cause crashes.
They also have a brief sample program that demonstrates some of this stuff.
As for why your signal handler is firing twice, I don't think that has to do with APR. SIGINT is sent to parent and child processes, so I suspect MyServer
is forking a new process and both are invoking the handler.