From 46bad27fffbc519616af933e2b71ac7b0b60e49e Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Fri, 22 May 2020 15:55:08 -0500 Subject: [PATCH] port remaining tests to std::mutex --- tests/base/task_11.cc | 8 ++++---- tests/base/thread_local_storage_05.cc | 12 ++++++------ tests/base/thread_local_storage_06.cc | 12 ++++++------ tests/base/thread_validity_08.cc | 8 ++++---- tests/base/thread_validity_09.cc | 8 ++++---- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/base/task_11.cc b/tests/base/task_11.cc index 96559b190c..1afc82aaf4 100644 --- a/tests/base/task_11.cc +++ b/tests/base/task_11.cc @@ -36,9 +36,9 @@ a_task() // here. std::this_thread::sleep_for(std::chrono::seconds(1)); - mutex.acquire(); + mutex.lock(); n_running--; - mutex.release(); + mutex.unlock(); } @@ -51,13 +51,13 @@ test() n_max_running = 0; // force all tasks to wait until we are done starting - mutex.acquire(); + mutex.lock(); for (unsigned int t = 0; t < 10; ++t) tg += Threads::new_task(a_task); // now let the tasks run - mutex.release(); + mutex.unlock(); tg.join_all(); } diff --git a/tests/base/thread_local_storage_05.cc b/tests/base/thread_local_storage_05.cc index e5d861358a..40b47f789e 100644 --- a/tests/base/thread_local_storage_05.cc +++ b/tests/base/thread_local_storage_05.cc @@ -51,8 +51,8 @@ execute(Threads::Mutex &m) AssertThrow(exists == true, ExcInternalError()); // wait for the barrier to clear - m.acquire(); - m.release(); + m.lock(); + m.unlock(); // at this point, the tls object should have been cleared and should // be back at its original value @@ -68,22 +68,22 @@ test() const unsigned int N = 10; Threads::Mutex m[N]; - // start N threads with mutices locked + // start N threads with mutexes locked Threads::ThreadGroup<> tg; for (unsigned int i = 0; i < N; ++i) { - m[i].acquire(); + m[i].lock(); tg += Threads::new_thread(execute, m[i]); } // let threads work through their first part std::this_thread::sleep_for(std::chrono::seconds(3)); - // then reset the thread local object and release the mutices so the + // then reset the thread local object and release the mutexes so the // threads can actually run to an end tls_data.clear(); for (unsigned int i = 0; i < N; ++i) - m[i].release(); + m[i].unlock(); // now make sure the threads all finish tg.join_all(); diff --git a/tests/base/thread_local_storage_06.cc b/tests/base/thread_local_storage_06.cc index ccf74a4fa4..005692ae8f 100644 --- a/tests/base/thread_local_storage_06.cc +++ b/tests/base/thread_local_storage_06.cc @@ -63,8 +63,8 @@ execute(Threads::Mutex &m) AssertThrow(exists == true, ExcInternalError()); // wait for the barrier to clear - m.acquire(); - m.release(); + m.lock(); + m.unlock(); // at this point, the tls object should have been cleared and should // be back at its original value @@ -80,22 +80,22 @@ test() const unsigned int N = 10; Threads::Mutex m[N]; - // start N threads with mutices locked + // start N threads with mutexes locked Threads::ThreadGroup<> tg; for (unsigned int i = 0; i < N; ++i) { - m[i].acquire(); + m[i].lock(); tg += Threads::new_thread(execute, m[i]); } // let threads work through their first part std::this_thread::sleep_for(std::chrono::seconds(3)); - // then reset the thread local object and release the mutices so the + // then reset the thread local object and release the mutexes so the // threads can actually run to an end tls_data.clear(); for (unsigned int i = 0; i < N; ++i) - m[i].release(); + m[i].unlock(); // now make sure the threads all finish tg.join_all(); diff --git a/tests/base/thread_validity_08.cc b/tests/base/thread_validity_08.cc index ba562c2d59..9bec1301d1 100644 --- a/tests/base/thread_validity_08.cc +++ b/tests/base/thread_validity_08.cc @@ -33,8 +33,8 @@ worker() // wait for the mutex to make sure the main // thread has already moved on. we can immediately // release the mutex again. - mutex.acquire(); - mutex.release(); + mutex.lock(); + mutex.unlock(); deallog << "OK." << std::endl; spin_lock = 1; } @@ -46,7 +46,7 @@ main() { initlog(); - mutex.acquire(); + mutex.lock(); // start and abandon the // thread. because we hold the // lock, the started task can not @@ -66,7 +66,7 @@ main() std::this_thread::sleep_for(std::chrono::seconds(1)); // let abandoned thread continue - mutex.release(); + mutex.unlock(); // wait for thread to finish while (spin_lock == 0) diff --git a/tests/base/thread_validity_09.cc b/tests/base/thread_validity_09.cc index 159895d45f..6c56e2e80a 100644 --- a/tests/base/thread_validity_09.cc +++ b/tests/base/thread_validity_09.cc @@ -38,10 +38,10 @@ worker() // mutex. release the mutex again at the end of this function since // mutices can only be released on the same thread as they are // acquired on. - mutex.acquire(); + mutex.lock(); deallog << "OK." << std::endl; spin_lock = 1; - mutex.release(); + mutex.unlock(); return 42; } @@ -52,7 +52,7 @@ main() { initlog(); - mutex.acquire(); + mutex.lock(); { Threads::new_thread(worker); } @@ -64,7 +64,7 @@ main() p[i] = 0; // make sure the worker thread can actually start - mutex.release(); + mutex.unlock(); // wait for the worker thread to do its work while (spin_lock == 0) -- 2.39.5