Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumC++threads and async basicsSingle-choice MCQ

Two threads each call get_future() and set_value() patterns. What is the defect in this producer/consumer code?

std::promise<int> p; std::thread prod([&]{ p.set_value(7); }); std::thread cons([&]{ auto fut = p.get_future(); std::cout << fut.get(); }); prod.join(); cons.join();