Use thread safe alternative to thread_local.

This is doable now that all use of thread_local (on objects) is for function static.