29 Jul
2009
29 Jul
'09
2:44 p.m.
jp wrote: [snip]
The problem I have with my implementation is that what I really want is a thread-local singleton. If I have to make the access threadsafe, then I may be better off recreating it every time. Any ideas on how best to do this? Could it be done with the boost::serialization singleton? My guess is that it may be possible by using the loki creation policy, but I have no idea how to go about doing it.
Perhaps using http://tinyurl.com/m2pukz? I.e., something like below (untested)? Kind regards, Rutger template< typename Singleton > Singleton& get_singleton() { static boost::thread_specific_ptr< Singleton > m_singleton; if ( !m_singleton.get() ) { m_singleton.reset( new Singleton() ); } return *m_singleton; }