You may also like to look at thread local storage. Compilers compliant with the new C++ standard can use thread_local. For older compilers you will have to rely on platform specific solutions.