From: Kefu Chai Date: Wed, 18 Aug 2021 06:06:55 +0000 (+0800) Subject: test/common/test_fair_mutex: s/std::thread/std::async()/ X-Git-Tag: v16.2.7~100^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=33ffe335fca503e6db06c62478f88a86e00cd04a;p=ceph.git test/common/test_fair_mutex: s/std::thread/std::async()/ for better readability, as we don't need to care about the details of the executor. and the returned futures are blocked in their dtor as > these actions will not block for the shared state to become ready, > except that it may block if all of the following are true: the > shared state was created by a call to std::async, the shared state > is not yet ready, and this was the last reference to the shared state. Signed-off-by: Kefu Chai (cherry picked from commit 4e35ac670bc75e3507777d4375bbbb0fea8533ba) --- diff --git a/src/test/common/test_fair_mutex.cc b/src/test/common/test_fair_mutex.cc index 1ee8b8ca4ac..2eaf67b54c3 100644 --- a/src/test/common/test_fair_mutex.cc +++ b/src/test/common/test_fair_mutex.cc @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include "common/fair_mutex.h" @@ -61,11 +61,8 @@ TEST(FairMutex, fair) }; } }; - std::array teams; + std::array, NR_TEAMS> completed; for (int team = 0; team < NR_TEAMS; team++) { - teams[team] = std::thread(play, team); - } - for (auto& team : teams) { - team.join(); + completed[team] = std::async(std::launch::async, play, team); } }