[Bug libstdc++/64144] New: std::async can deadlock during thread exit

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Dec 1 19:25:00 GMT 2014


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

            Bug ID: 64144
           Summary: std::async can deadlock during thread exit
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org

#include <future>

std::future<void> fut;

struct A {
  ~A() { fut.wait(); }
};

thread_local A a;

void f() { (void)&a; }

int main()
{
  fut = std::async(std::launch::async, f);
}


While the async thread is exiting the thread local destructor checks the status
of the future, detects it is ready, then blocks waiting for the thread to exit,
which won't happen until the destructor finishes.



More information about the Gcc-bugs mailing list