http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54297

             Bug #: 54297
           Summary: [C++11] Segmentation fault with std::async and
                    released shared state
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: ai.az...@gmail.com


Created attachment 28043
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28043
Command-line log

The following code causes segfault with GCC 4.8.0 20120812, -std=c++11 and
-pthread.

/////////////////////////////////////////////////////////////
#include <chrono>
#include <thread>
#include <future>

int work()
{
  std::this_thread::sleep_for(std::chrono::seconds(1));
  return 0;
}

int main()
{
  // Note that the following explicitly named future object
  // is not necessary to reproduce the problem.
  std::future<int> f = std::async(std::launch::async, &work);
}
/////////////////////////////////////////////////////////////

The last invocation of std::future<int>'s destructor blocks the calling thread
until the thread launched by std::async finishes the work, according to the 4th
bullet of [futures.async]/5. Therefore, this program should terminate
successfully.

This program also results in segfault with GCC 4.7.2 20120811, but not with
4.6.4 20120810.

Reply via email to