I am writing a shared library that will allow related applications to request a resource.
The resource class is implemented only using static methods (see below). It also uses a global object (with full coverage of the anonymous namespace). The reason for the global variable is that I do not want to expose the system internals to users of the library. I suppose I could use the pimpl idiom, but that still does not address the thread safety issue.
The class looks something like this:
Some of the applications using this library will be multithreaded and, thus, can call methods on A from different threads.
So my question is how to implement globvar to be thread safe?
I am developing using gcc 4.4.1 on Ubuntu 9.10
source share