mercredi 6 septembre 2017

clang & stdc++: potential c++ future/promise bug

Just played a bit on Mac OS Sierra (10.12.6) with Clang and stdc++

$ clang++ --version
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Applications/http://ift.tt/1z8WHIF

Here is stated: http://ift.tt/2gGwIF4:

Abandons the shared state:

  • if the shared state is ready, releases it.
  • if the shared state is not ready, stores an exception object of type std::future_error with an error condition std::future_errc::broken_promise, makes the shared state ready and releases it.

IMO, it's pretty obvious that if promise is destroyed future::get() must raise and exception and cancel the waiting. This C++ code blocks and no exception is raised:

auto p = std::make_unique<std::promise<std::string>>();

// getting a future and deleting the promise should make that 
// future ready and raise an exception
{
  auto f = p->get_future();

  p.release();
  f.get();  // must raise an exception
}

Did I just find a bug in stdc++ lib implementation?

Aucun commentaire:

Enregistrer un commentaire