#include <SharedStaticData.h>
Public Member Functions | |
nonvirtual T & | Get () |
SharedStaticData<T> is used to safely create a copy of static data shared among various users in a thread safe way, and where the shared data goes away when the last reference does, and where the shared data is lazy constructed.
This is very similar to have a single static variable of type T, except that instead of having T constructed at global execution time, and destroyed at global object destruction time, it happens when the first owner comes into existence and when the last owner goes out of existence.
For example - if the shared data object creates threads, it can be a problem having this destroyed in a static (file scope) lifetime.
This can be important, if, for example, the shared object contains Thread objects.
So then on the first AuditLogSink construction - we construct the cleanup thread, and on the last the thread is shutdown. If these objects are all created after main, this assures the thread startup/cleanup is all done after the start of main and before it completes.
Definition at line 85 of file SharedStaticData.h.
T & Stroika::Foundation::Execution::SharedStaticData< T >::Get | ( | ) |
Return value guaranteed lifetime at least as long as 'this' object.
Note - though THIS is fully threadsafe, use of the reference T& is only as threadsafe as T itself.
Definition at line 38 of file SharedStaticData.inl.