* @brief Test recursive mutex allowing multiple locks by the same thread. */
| 42 | * @brief Test recursive mutex allowing multiple locks by the same thread. |
| 43 | */ |
| 44 | static 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. |