10 #include <gtest/gtest.h> 11 #include <mrpt/config.h> 16 #include <condition_variable> 19 #if !defined(MRPT_OS_APPLE) 23 const std::string testValue =
"CoolName";
24 const std::string testValue2 =
"HotName";
38 static std::condition_variable
cv,
cv2;
49 std::lock_guard<std::mutex> lk(
cv2_m);
56 std::unique_lock<std::mutex> lk(
cv_m);
57 cv.wait(lk, [&]() {
return thrCnt == 0; });
68 std::lock_guard<std::mutex> lk(
cv2_m);
75 std::unique_lock<std::mutex> lk(
cv_m);
76 cv.wait(lk, [&]() {
return thrDone == 0; });
82 constexpr
unsigned int N = 10;
83 std::vector<std::thread> threads;
84 std::vector<std::string>
names;
86 for (
unsigned int i = 0; i < N; i++)
89 std::thread& t = threads.emplace_back(&
testerThread, thName);
90 names.push_back(thName);
97 std::unique_lock<std::mutex> lk(
cv2_m);
98 cv2.wait(lk, [&] {
return thrCnt == N; });
103 std::lock_guard<std::mutex> lk(
cv_m);
109 std::unique_lock<std::mutex> lk(
cv2_m);
113 for (
auto& t : threads)
119 std::lock_guard<std::mutex> lk(
cv_m);
124 for (
auto& t : threads)
125 if (t.joinable()) t.join();
std::string std::string format(std::string_view fmt, ARGS &&... args)
static std::condition_variable cv2
static std::atomic< int > thrCnt
void thread_name(const std::string &name, std::thread &theThread)
Sets the name of the given thread; useful for debuggers.
TEST(thread_name, set_get_current_thread)
static std::atomic< int > thrDone
std::vector< string > names
static std::condition_variable cv
EXPECT_EQ(out.image_pair_was_used.size(), NUM_IMGS)
static const std::string sNewName
static void testerThread(const std::string &myName)