MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / test_recursive_mutex

Function test_recursive_mutex

components/libc/cplusplus/utest/tc_mutex.cpp:44–68  ·  view source on GitHub ↗

* @brief Test recursive mutex allowing multiple locks by the same thread. */

Source from the content-addressed store, hash-verified

42 * @brief Test recursive mutex allowing multiple locks by the same thread.
43 */
44static void test_recursive_mutex(void)
45{
46 std::recursive_mutex rm;
47 int count = 0;
48 auto func = [&]() mutable {
49 std::lock_guard<std::recursive_mutex> lock1(rm);
50 std::lock_guard<std::recursive_mutex> lock2(rm);
51 for (int i = 0; i < 1000; ++i)
52 {
53 ++count;
54 }
55 };
56
57 std::thread t1(func);
58 std::thread t2(func);
59
60 t1.join();
61 t2.join();
62
63 if (count != 2000)
64 {
65 uassert_false(true);
66 }
67 uassert_true(true);
68}
69
70/**
71 * @brief Test try_lock on mutex.

Callers

nothing calls this directly

Calls 1

joinMethod · 0.45

Tested by

no test coverage detected