News for hackers. Stuff that matters.
Re:Mistakes to avoid with C++ 11 smart pointers by Kristine1975 on Sunday May 15, 2016 @01:39AM (#11699605)
Mistake #10 contains a race condition when another thread destroys the last shared_ptr to pIceman (Top Gun fan much?) between the call to !pMaverick->myWingMan.expired() and pMaverick->myWingMan.lock().

Just use:

  if (auto p = pMaverick->myWingMan.lock())
    p->take_shower_with(pMaverick);
See http://en.cppreference.com/w/cpp/memory/weak_ptr/lock

There are no comments on this comment yet.