[llvm-bugs] [Bug 24692] New: promise/future deadlock

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Sep 3 07:03:57 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=24692

            Bug ID: 24692
           Summary: promise/future deadlock
           Product: libc++
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: kaballo86 at hotmail.com
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com
    Classification: Unclassified

The following test case results in a deadlock:

    #include <chrono>
    #include <future>
    #include <iostream>
    #include <utility>

    template <typename T>
    struct weird {
      std::future<weird<T>> f;

      explicit weird(std::future<weird<T>> f) : f(std::move(f)) {}

      weird(weird&& other)
        : f(std::move(other.f))
      {
        if (f.wait_for(std::chrono::seconds(1)) == std::future_status::timeout)
{
          std::cout << "Moving but the future is not ready yet\n";
        }
      }
    };

    int main() {
      std::promise<weird<int>> p;
      weird<int> w(p.get_future());
      p.set_value(std::move(w));
    }

This is caused by executing arbitrary user code under a lock.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150903/d0cbccee/attachment.html>


More information about the llvm-bugs mailing list