I have a property similar to the following:
private: Foo* myFoo_m; public: Foo getMyFoo() const { if (myFoo_m == NULL) { myFoo_m = new Foo();
This works well in a single-threaded environment, but how can I handle this in a multi-threaded environment? Most of the information I found relates to static singlets, but in this case, myFoo is a public instance property.
I port this with C # (where I can use Lazy) and Java (where I can use double check lock), but there seems to be no easy way to do this in C ++. I can not rely on external libraries (without BOOST), and this is necessary for working with windows and linux. I also can not use C ++ 11.
Any insight would be good. I am new to C ++.
source share