mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2025-12-17 12:44:42 +03:00
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:
@@ -14124,12 +14124,11 @@ Application concepts are easier to reason about.
|
||||
|
||||
##### Example
|
||||
|
||||
void some_fun()
|
||||
void some_fun(const std::string& msg)
|
||||
{
|
||||
std::string msg, msg2;
|
||||
std::thread publisher([&] { msg = "Hello"; }); // bad: less expressive
|
||||
std::thread publisher([=] { std::cout << msg; }); // bad: less expressive
|
||||
// and more error-prone
|
||||
auto pubtask = std::async([&] { msg2 = "Hello"; }); // OK
|
||||
auto pubtask = std::async([=] { std::cout << msg; }); // OK
|
||||
// ...
|
||||
publisher.join();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user