https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92731
--- Comment #4 from Lasse Reinhold <rrrlasse at hotmail dot com> --- Some simplifications, and also tried with atomics instead of mutexes, to no avail: #include <iostream> #include <stdexcept> #include <future> #include <assert.h> std::function<void()> job; std::atomic<bool> has_job{ false }; int main() { std::thread t = std::thread([]() { for (;;) { if (has_job.load(std::memory_order_acquire)) { job(); has_job.store(false, std::memory_order_release); } } }); for (int c = 0; ; c++) { if (!has_job.load(std::memory_order_acquire)) { try { std::packaged_task<void()> packaged_task([]() { throw 1234; }); std::future<void> task_future = packaged_task.get_future(); job = [&]() { std::packaged_task<void ()> tmp(std::move(packaged_task)); tmp(); }; has_job.store(true, std::memory_order_release); task_future.get(); } catch (const int& e) { assert(e == 1234); } } } }