https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99356

            Bug ID: 99356
           Summary: Recursive std::shared_future:s with
                    std::launch::deferred sporadically deadlock
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fiesh at zefix dot tv
  Target Milestone: ---

Trying to sail around 97949, we switched to using std::shared_future combined
with std::launch::deferred instead of using std::call_once.

Now again this leads to sporadic deadlocks under Windows.

The following code exemplifies the behavior:

----------------------------------------

#include <chrono>
#include <future>
#include <iostream>
#include <thread>

int main() {
  auto const future0 =
      std::shared_future<void>{std::async(std::launch::deferred, []() {
        using namespace std::chrono_literals;
        std::cout << "future0 running..." << std::endl;
        std::this_thread::sleep_for(1s);
        std::cout << "future0 done." << std::endl;
      })};

  auto const future1 =
      std::shared_future<void>{std::async(std::launch::deferred, [future0]() {
        std::cout << "future0 running..." << std::endl;
        future0.get();
        std::cout << "future0 done." << std::endl;
      })};

  auto const getFuture = [future1]() {
    std::cout << "getting future1..." << std::endl;
    future1.get();
    std::cout << "got future1." << std::endl;
  };

  std::thread t0(getFuture);
  std::thread t1(getFuture);

  t0.join();
  t1.join();

  std::cout << "done" << std::endl;
}

----------------------------------------

If there's a workaround, we'd be very grateful.

Reply via email to