Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

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


Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: