Threads::ThreadMutex mutex;
-void test ()
+void test ()
{
- // get the mutex, but note that it is first
- // held by main() which will therefore
- // usually get to write to deallog first
+ // get the mutex, but note that it is first
+ // held by main() which will therefore
+ // usually get to write to deallog first
mutex.acquire();
deallog << "2" << std::endl;
}
-
+
int main()
{
std::ofstream logfile("mutex_01/output");
deallog.depth_console(0);
deallog.threshold_double(1.e-10);
- if (DEAL_II_USE_MT != 0)
- {
- mutex.acquire ();
-
- Threads::Thread<> t = Threads::new_thread (&test);
-
- sleep (2);
- deallog << "1" << std::endl;
-
- mutex.release ();
- t.join ();
-
- // the other thread should now have
- // acquired the mutex, so release
- // it again (destroying an acquired
- // lock invokes undefined behavior
- // in pthread_mutex_destroy)
- mutex.release ();
- }
- else
- {
- // make sure the test also
- // works in non-MT mode
- deallog << "1" << std::endl;
- deallog << "2" << std::endl;
- }
+#ifdef DEAL_II_USE_MT
+
+ mutex.acquire ();
+
+ Threads::Thread<> t = Threads::new_thread (&test);
+
+ sleep (2);
+ deallog << "1" << std::endl;
+
+ mutex.release ();
+ t.join ();
+
+ // the other thread should now have acquired the mutex, so release it
+ // again (destroying an acquired lock invokes undefined behavior in
+ // pthread_mutex_destroy)
+ mutex.release ();
+
+#else
+
+ // make sure the test also works in non-MT mode
+ deallog << "1" << std::endl;
+ deallog << "2" << std::endl;
+#endif
}