I think by calling apr_initialize every time you may well render it no-longer threadsafe...

You don't need a function to tell you if you have called it yet or not - a static boolean variable will do.

My concern with atexit was that you were calling it multiple times - this means it will be called multiple times at exit.

I suspect given our intended usage that simply wrapping the entire function in a critsec would be simple and safe enough, and use a try/catch to ensure that you call the apr_terminate whatever (and get rid of the atexit)