c++ - Loki's SetLongevity function seems unsafe to me, is that so? -
there global variable called "ptrackerarray", used in loki's setlongevity function.
declaration of ptrackerarray:
typedef std::list<lifetimetracker*> trackerarray; extern loki_export trackerarray* ptrackerarray;
definition of setlongevity:
template <typename t, typename destroyer> void setlongevity(t* pdynobject, unsigned int longevity, destroyer d) { using namespace private; // manage lifetime of stack manually if(ptrackerarray==0) ptrackerarray = new trackerarray; // simplicity, rest of code omitted ... }
is thread safe use ptrackerarray such in setlongevity?
as shown, not. however, if reading rest of file correctly, setlongevity
is, ultimately, ever called within function wrapped in mutex [provided requested singleton thread-safe, obviously]. so while particular function has issues, use still safe.
however, mutex create in base function paramaterized on type of singleton creating, while global pointer shared between singletons. yes, appear though 2 different singleton objects in 2 different threads both access function @ once, causing havok.
Comments
Post a Comment