Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumC++shared_ptr and weak_ptrSingle-choice MCQ

Why is `wp.expired()` followed by `wp.lock()` a race-prone pattern in multithreaded code, while `lock()` alone is safe?

if (!wp.expired()) { auto sp = wp.lock(); // (!) object may have died between the two calls sp->use(); }