From: Daniel Arndt Date: Wed, 30 May 2018 11:25:21 +0000 (+0200) Subject: Avoid using unistd.h and sleep X-Git-Tag: v9.1.0-rc1~1083^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f0d93ed59d97a7c05b467167fcbfd60a15ea6f97;p=dealii.git Avoid using unistd.h and sleep --- diff --git a/tests/base/mutex_01.cc b/tests/base/mutex_01.cc index 348bed2e78..0b4979bac5 100644 --- a/tests/base/mutex_01.cc +++ b/tests/base/mutex_01.cc @@ -18,8 +18,6 @@ #include -#include - #include "../tests.h" @@ -48,7 +46,7 @@ main() Threads::Thread<> t = Threads::new_thread(&test); - sleep(2); + std::this_thread::sleep_for(std::chrono::seconds(2)); deallog << "1" << std::endl; mutex.release(); diff --git a/tests/base/task_01.cc b/tests/base/task_01.cc index 3c8172fe16..ad9e47e588 100644 --- a/tests/base/task_01.cc +++ b/tests/base/task_01.cc @@ -20,15 +20,13 @@ #include -#include - #include "../tests.h" void test() { - sleep(3); + std::this_thread::sleep_for(std::chrono::seconds(3)); deallog << "OK" << std::endl; } diff --git a/tests/base/task_02.cc b/tests/base/task_02.cc index 4390171384..eaae3e8cd7 100644 --- a/tests/base/task_02.cc +++ b/tests/base/task_02.cc @@ -18,15 +18,13 @@ #include -#include - #include "../tests.h" int test() { - sleep(3); + std::this_thread::sleep_for(std::chrono::seconds(3)); return 42; } diff --git a/tests/base/task_03.cc b/tests/base/task_03.cc index 12faacdc4a..b852cc6731 100644 --- a/tests/base/task_03.cc +++ b/tests/base/task_03.cc @@ -19,8 +19,6 @@ #include -#include - #include "../tests.h" @@ -28,7 +26,7 @@ void test(int i) { deallog << "Task " << i << " starting..." << std::endl; - sleep(1); + std::this_thread::sleep_for(std::chrono::seconds(1)); deallog << "Task " << i << " finished!" << std::endl; } diff --git a/tests/base/task_04.cc b/tests/base/task_04.cc index aade6c83db..babca60e6e 100644 --- a/tests/base/task_04.cc +++ b/tests/base/task_04.cc @@ -18,8 +18,6 @@ #include -#include - #include "../tests.h" @@ -37,7 +35,7 @@ test(int i) t2.join(); } - sleep(1); + std::this_thread::sleep_for(std::chrono::seconds(1)); deallog << "Task " << i << " finished!" << std::endl; } diff --git a/tests/base/task_05.cc b/tests/base/task_05.cc index 9427c6ce44..358935f924 100644 --- a/tests/base/task_05.cc +++ b/tests/base/task_05.cc @@ -25,8 +25,6 @@ #include -#include - #include "../tests.h" diff --git a/tests/base/task_06.cc b/tests/base/task_06.cc index 2f63e61157..ba49b77c86 100644 --- a/tests/base/task_06.cc +++ b/tests/base/task_06.cc @@ -19,8 +19,6 @@ #include -#include - #include "../tests.h" @@ -28,7 +26,7 @@ void test(int i) { deallog << "Task " << i << " starting..." << std::endl; - sleep(1); + std::this_thread::sleep_for(std::chrono::seconds(1)); if (i < 10) { Threads::new_task(test, 10 + i).join(); diff --git a/tests/base/task_07.cc b/tests/base/task_07.cc index 34cdf21005..7a668fae73 100644 --- a/tests/base/task_07.cc +++ b/tests/base/task_07.cc @@ -18,8 +18,6 @@ #include -#include - #include "../tests.h" @@ -27,7 +25,7 @@ void test(int i) { deallog << "Task " << i << " starting..." << std::endl; - sleep(1); + std::this_thread::sleep_for(std::chrono::seconds(1)); deallog << "Task " << i << " finished!" << std::endl; } diff --git a/tests/base/task_08.cc b/tests/base/task_08.cc index 7d5697b7dd..05e3051c16 100644 --- a/tests/base/task_08.cc +++ b/tests/base/task_08.cc @@ -20,15 +20,13 @@ #include -#include - #include "../tests.h" void test(int i) { - sleep(1); + std::this_thread::sleep_for(std::chrono::seconds(1)); deallog << "Task " << i << " finished!" << std::endl; } diff --git a/tests/base/task_10.cc b/tests/base/task_10.cc index 0704a38c83..e59a48dc8e 100644 --- a/tests/base/task_10.cc +++ b/tests/base/task_10.cc @@ -18,15 +18,13 @@ #include -#include - #include "../tests.h" void test() { - sleep(3); + std::this_thread::sleep_for(std::chrono::seconds(1)); deallog << "OK" << std::endl; } diff --git a/tests/base/task_11.cc b/tests/base/task_11.cc index f57bd27e5a..d9eaf588c5 100644 --- a/tests/base/task_11.cc +++ b/tests/base/task_11.cc @@ -18,8 +18,6 @@ #include -#include - #include "../tests.h" Threads::Mutex mutex; @@ -36,7 +34,7 @@ a_task() // Sleep some time to make sure all other concurrently running tasks enter // here. - sleep(1); + std::this_thread::sleep_for(std::chrono::seconds(1)); mutex.acquire(); n_running--; diff --git a/tests/base/task_12.cc b/tests/base/task_12.cc index c8127f3596..f6e54dd763 100644 --- a/tests/base/task_12.cc +++ b/tests/base/task_12.cc @@ -19,8 +19,6 @@ #include -#include - #include "../tests.h" @@ -30,7 +28,7 @@ double test(int i) { deallog << "Task " << i << " starting..." << std::endl; - sleep(1); + std::this_thread::sleep_for(std::chrono::seconds(1)); deallog << "Task " << i << " finished!" << std::endl; return 3.141; diff --git a/tests/base/task_12_capture.cc b/tests/base/task_12_capture.cc index 179a9704bb..52d2204086 100644 --- a/tests/base/task_12_capture.cc +++ b/tests/base/task_12_capture.cc @@ -22,8 +22,6 @@ #include -#include - #include "../tests.h" @@ -33,7 +31,7 @@ double test(int i) { deallog << "Task " << i << " starting..." << std::endl; - sleep(1); + std::this_thread::sleep_for(std::chrono::seconds(1)); deallog << "Task " << i << " finished!" << std::endl; return 3.141; diff --git a/tests/base/task_13.cc b/tests/base/task_13.cc index 6d9d4b2ac8..c7fa56d8f8 100644 --- a/tests/base/task_13.cc +++ b/tests/base/task_13.cc @@ -22,8 +22,6 @@ #include -#include - #include "../tests.h" @@ -33,7 +31,7 @@ double test(int i) { deallog << "Task " << i << " starting..." << std::endl; - sleep(1); + std::this_thread::sleep_for(std::chrono::seconds(1)); deallog << "Task " << i << " finished!" << std::endl; return 3.141; diff --git a/tests/base/thread_12.cc b/tests/base/thread_12.cc index 1b9e152ad1..bbd0a8d579 100644 --- a/tests/base/thread_12.cc +++ b/tests/base/thread_12.cc @@ -19,8 +19,6 @@ #include -#include - #include "../tests.h" @@ -30,7 +28,7 @@ double test(int i) { deallog << "Task " << i << " starting..." << std::endl; - sleep(1); + std::this_thread::sleep_for(std::chrono::seconds(1)); deallog << "Task " << i << " finished!" << std::endl; return 3.141; diff --git a/tests/base/thread_local_storage_01.cc b/tests/base/thread_local_storage_01.cc index f4daae2284..79eddf2226 100644 --- a/tests/base/thread_local_storage_01.cc +++ b/tests/base/thread_local_storage_01.cc @@ -56,7 +56,7 @@ execute(int i) // wait in order to make sure that the // thread lives longer than the TLS object - sleep(5); + std::this_thread::sleep_for(std::chrono::seconds(5)); } diff --git a/tests/base/thread_local_storage_02.cc b/tests/base/thread_local_storage_02.cc index c22136c3e9..1b8b464b89 100644 --- a/tests/base/thread_local_storage_02.cc +++ b/tests/base/thread_local_storage_02.cc @@ -66,7 +66,7 @@ execute(int i) // wait in order to make sure that the // thread lives longer than the TLS object - sleep(5); + std::this_thread::sleep_for(std::chrono::seconds(5)); } diff --git a/tests/base/thread_local_storage_05.cc b/tests/base/thread_local_storage_05.cc index ee4d918322..013fbdb97e 100644 --- a/tests/base/thread_local_storage_05.cc +++ b/tests/base/thread_local_storage_05.cc @@ -19,8 +19,6 @@ #include #include -#include - #include "../tests.h" @@ -78,7 +76,7 @@ test() } // let threads work through their first part - sleep(3); + std::this_thread::sleep_for(std::chrono::seconds(3)); // then reset the thread local object and release the mutices so the // threads can actually run to an end diff --git a/tests/base/thread_local_storage_06.cc b/tests/base/thread_local_storage_06.cc index e2f0c1c140..3c78292016 100644 --- a/tests/base/thread_local_storage_06.cc +++ b/tests/base/thread_local_storage_06.cc @@ -20,8 +20,6 @@ #include #include -#include - #include "../tests.h" @@ -90,7 +88,7 @@ test() } // let threads work through their first part - sleep(3); + std::this_thread::sleep_for(std::chrono::seconds(3)); // then reset the thread local object and release the mutices so the // threads can actually run to an end diff --git a/tests/base/thread_validity_07.cc b/tests/base/thread_validity_07.cc index ae72e5400a..0bc359bd6b 100644 --- a/tests/base/thread_validity_07.cc +++ b/tests/base/thread_validity_07.cc @@ -19,8 +19,6 @@ #include -#include - #include "../tests.h" @@ -28,7 +26,7 @@ void worker() { deallog << "Worker thread is starting." << std::endl; - sleep(3); + std::this_thread::sleep_for(std::chrono::seconds(3)); deallog << "Worker thread is finished." << std::endl; } diff --git a/tests/base/thread_validity_08.cc b/tests/base/thread_validity_08.cc index dabfa5b3e5..795f10bd9c 100644 --- a/tests/base/thread_validity_08.cc +++ b/tests/base/thread_validity_08.cc @@ -18,8 +18,6 @@ #include -#include - #include #include "../tests.h" @@ -65,7 +63,7 @@ main() { Threads::new_thread(worker); } - sleep(1); + std::this_thread::sleep_for(std::chrono::seconds(1)); // let abandoned thread continue mutex.release(); diff --git a/tests/base/thread_validity_09.cc b/tests/base/thread_validity_09.cc index 719e1bf715..b4c157b733 100644 --- a/tests/base/thread_validity_09.cc +++ b/tests/base/thread_validity_09.cc @@ -21,8 +21,6 @@ #include -#include - #include #include "../tests.h" @@ -58,7 +56,7 @@ main() { Threads::new_thread(worker); } - sleep(1); + std::this_thread::sleep_for(std::chrono::seconds(1)); const unsigned int sz = 1000000; char * p = new char[sz]; diff --git a/tests/base/thread_validity_10.cc b/tests/base/thread_validity_10.cc index 273bba122e..4f8ffd88df 100644 --- a/tests/base/thread_validity_10.cc +++ b/tests/base/thread_validity_10.cc @@ -19,8 +19,6 @@ #include -#include - #include "../tests.h" @@ -31,7 +29,7 @@ int spin_lock = 0; int worker() { - sleep(1); + std::this_thread::sleep_for(std::chrono::seconds(1)); return 42; } diff --git a/tests/base/thread_validity_13.cc b/tests/base/thread_validity_13.cc index 9e44f873a9..32aa736ec3 100644 --- a/tests/base/thread_validity_13.cc +++ b/tests/base/thread_validity_13.cc @@ -21,8 +21,6 @@ #include -#include - #include "../tests.h" diff --git a/tests/base/thread_validity_14.cc b/tests/base/thread_validity_14.cc index d6ee4715bd..a4fba249f2 100644 --- a/tests/base/thread_validity_14.cc +++ b/tests/base/thread_validity_14.cc @@ -21,8 +21,6 @@ #include -#include - #include "../tests.h" diff --git a/tests/mpi/no_flux_constraints_02.cc b/tests/mpi/no_flux_constraints_02.cc index 159ee7a504..de07444dc2 100644 --- a/tests/mpi/no_flux_constraints_02.cc +++ b/tests/mpi/no_flux_constraints_02.cc @@ -135,7 +135,7 @@ test() constraints.print(file); } MPI_Barrier(MPI_COMM_WORLD); - sleep(1); + std::this_thread::sleep_for(std::chrono::seconds(1)); if (myid == 0) { // sort and merge the constraint matrices on proc 0, generate a checksum diff --git a/tests/mpi/no_flux_constraints_03.cc b/tests/mpi/no_flux_constraints_03.cc index dddecc3f96..ca051afc77 100644 --- a/tests/mpi/no_flux_constraints_03.cc +++ b/tests/mpi/no_flux_constraints_03.cc @@ -108,7 +108,7 @@ test() constraints.print(file); } MPI_Barrier(MPI_COMM_WORLD); - sleep(1); + std::this_thread::sleep_for(std::chrono::seconds(1)); if (myid == 0) { // sort and merge the constraint matrices on proc 0, generate a checksum diff --git a/tests/mpi/simple_mpi_01.cc b/tests/mpi/simple_mpi_01.cc index e5f2eba5c1..983423608f 100644 --- a/tests/mpi/simple_mpi_01.cc +++ b/tests/mpi/simple_mpi_01.cc @@ -39,7 +39,6 @@ test_mpi() for (unsigned int i = 1; i < numprocs; ++i) { MPI_Barrier(MPI_COMM_WORLD); - // system("sleep 1"); if (myid == 0) { diff --git a/tests/mpi/trilinos_01.cc b/tests/mpi/trilinos_01.cc index ab8baa1067..708e724fac 100644 --- a/tests/mpi/trilinos_01.cc +++ b/tests/mpi/trilinos_01.cc @@ -71,7 +71,7 @@ test() MPI_Iprobe(0, 12345, MPI_COMM_WORLD, &flag, &status); std::cout << flag << std::endl; - sleep(1); + std::this_thread::sleep_for(std::chrono::seconds(1)); } Assert(flag != 0, ExcMessage("hang in has_ghost_elements()"));