* @brief Test basic mutex operations with lock_guard. */
| 18 | * @brief Test basic mutex operations with lock_guard. |
| 19 | */ |
| 20 | static 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. |