
Dave Handley wrote:
I would have normally expected singleton creation to be handled with a lazy creation policy. This means that they are not created until used, and if not used never created. Then destruction would take place with the standard destruction policy. If you want to force creation at an earlier stage in the program execution then just call GetInstance() and throw away the result.
Ok, thanks for clearing that up.
BTW, regarding your concerns on integrating with say boost.thread, why not place all dependencies under a pre-processor guard, that enables threading. Then if you want to enable threading, you would set the pre-processor guard (like the smart pointers implementations), but also include the correct policy in your template specification. This means that under those circumstances where you want both threaded and un-threaded singletons, you can achieve this by turning on the boost directive, and using the policies accordingly. Without the pre-processor directive you simply would not have access to the multi-threaded policies.
What would be the problem with just putting policies involving multi-threading separate headers? I think that #include <singleton.h> #include <singleton_multithreaded_policies.h> is clearer than #define USING_SINGLETON_MULTITHREADED #include <singleton.h> and separates dependencies better. -Jason