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

            Bug ID: 28285
           Summary: std::async with default policy moves their arguments
                    twice if std::thread cannot be created
           Product: libc++
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangb...@nondot.org
          Reporter: kariya_mits...@hotmail.com
                CC: llvm-bugs@lists.llvm.org, mclow.li...@gmail.com
    Classification: Unclassified

In the libc++'s current implementation of std::async with default policy (i.e.
async | deferred),
first, the argument function is launched in the context of a new thread
asynchronously (async).
If it was failed, the function is launched in the context of the current thread
later (deffered).

But if the first launch was failed (ex. std::thread creation trows an
exception), std::async's
arguments was already moved.
So, the arguments have no valid values when second launch is executing.


The sample code below simulates std::thread creation failure.

============================== sample code ==============================
#include <iostream>
#include <future>
#include <string>
#include <system_error>

struct S {
    S() : b(false) {}
    // to simulate thread creation failure, it throws
resource_unavailable_try_again when 'o' is first move target
    S(S&& o) : b(true) {
        if (!o.b) {
            o.b = true;
            throw
std::system_error(std::make_error_code(std::errc::resource_unavailable_try_again));
        }
    }
    S(const S&) = delete;
    S& operator=(const S&) = delete;
    S&& operator=(S&&) = delete;
    bool b;
};

int main()
{
    auto f = std::async([](std::string&& s, S&&){ std::cout << "s = '" << s <<
'\'' << std::endl; }, std::string{"str"}, S{});
    f.get();
}
============================== sample code ==============================
============================== output ==============================
s = ''
============================== output ==============================
cf. http://melpon.org/wandbox/permlink/IZDRW8D7i0wifN91


I think that it should output "s = 'str'" or should output nothing,
whether exception is thrown or not.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to