Improve example in CP.4 to not contradict F.53. (#1724)

Changed the example so that objects are not passed by reference to other thread contexts (though threads are properly synchronized).
This commit is contained in:
Florian Behrens
2021-01-21 20:38:19 +01:00
committed by GitHub
parent b5412f5922
commit c142bc9d7e

View File

@@ -14124,12 +14124,11 @@ Application concepts are easier to reason about.
##### Example ##### Example
void some_fun() void some_fun(const std::string& msg)
{ {
std::string msg, msg2; std::thread publisher([=] { std::cout << msg; }); // bad: less expressive
std::thread publisher([&] { msg = "Hello"; }); // bad: less expressive
// and more error-prone // and more error-prone
auto pubtask = std::async([&] { msg2 = "Hello"; }); // OK auto pubtask = std::async([=] { std::cout << msg; }); // OK
// ... // ...
publisher.join(); publisher.join();
} }