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

Function test_mutex

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

* @brief Test basic mutex operations with lock_guard. */

Source from the content-addressed store, hash-verified

18 * @brief Test basic mutex operations with lock_guard.
19 */
20static void test_mutex(void)
21{
22 std::mutex m;
23 int count = 0;
24 auto func = [&]() mutable {
25 std::lock_guard<std::mutex> lock(m);
26 for (int i = 0; i < 1000; ++i)
27 {
28 ++count;
29 }
30 };
31
32 std::thread t1(func);
33 std::thread t2(func);
34
35 t1.join();
36 t2.join();
37
38 uassert_int_equal(count, 2000);
39}
40
41/**
42 * @brief Test recursive mutex allowing multiple locks by the same thread.

Callers

nothing calls this directly

Calls 1

joinMethod · 0.45

Tested by

no test coverage detected