Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 11: std::barrier requires a completion function not to throw an exception #4

Open
puhach opened this issue Jul 30, 2021 · 0 comments

Comments

@puhach
Copy link

puhach commented Jul 30, 2021

Building chapter 11 fails with the following errors on MSVC 2019:

1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\barrier(76,13): error C2338: N4861 [thread.barrier.class]/5: is_nothrow_invocable_v<CompletionFunction&> shall be true
1>C:\temp\Cpp-High-Performance-Second-Edition-master\Chapter11\barriers.cpp(38): message : see reference to class template instantiation 'std::barrier<Barriers_ForkJoin_Test::TestBody::<lambda_1>>' being compiled
1>Done building project "Chapter11-Concurrency.vcxproj" -- FAILED.

This is due to the check_result function not being declared noexcept:

  auto check_result = [&] { // Completion function
    ++n_turns;
    auto is_six = [](auto i) { return i == 6; };
    done = std::all_of(dice.begin(), dice.end(), is_six);
  };
  auto bar = std::barrier{n, check_result};

To fix the issue, change it to auto check_result = [&] () noexcept { ... }.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant