#include #include #include #include #include int main() { std::mutex mutex; std::condition_variable changed; bool ready = false; int answer = 0; { std::jthread worker([&] { const int computed = 6 * 7; { std::lock_guard lock(mutex); answer = computed; ready = true; } changed.notify_one(); }); std::unique_lock lock(mutex); changed.wait(lock, [&] { return ready; }); assert(answer == 42); std::cout << answer << "\n"; } }