From c142bc9d7e66ec11bbf5089159b9c2cd2f934a12 Mon Sep 17 00:00:00 2001 From: Florian Behrens Date: Thu, 21 Jan 2021 20:38:19 +0100 Subject: [PATCH] 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). --- CppCoreGuidelines.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index c0207b0..a15aa16 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -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 - // and more error-prone - auto pubtask = std::async([&] { msg2 = "Hello"; }); // OK + std::thread publisher([=] { std::cout << msg; }); // bad: less expressive + // and more error-prone + auto pubtask = std::async([=] { std::cout << msg; }); // OK // ... publisher.join(); }