Use C++11 features: thread-local storage.