]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Work around a POSIX violation.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 3 Oct 2013 23:52:35 +0000 (23:52 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 3 Oct 2013 23:52:35 +0000 (23:52 +0000)
git-svn-id: https://svn.dealii.org/branches/branch_port_the_testsuite@31114 0785d39b-7218-0410-832d-ea1e28bc413d

tests/base/thread_validity_09.cc

index 3daddafba0c922295898a38bd515f577ddb1c8a5..60d3247d9c263e156e86cb94cf828f6d616fea18 100644 (file)
@@ -34,9 +34,15 @@ int spin_lock = 0;
 
 int worker ()
 {
+  // wait till the main thread has actually done its work -- we will
+  // hang in the 'acquire' line until the main thread releases the
+  // mutex. release the mutex again at the end of this function since
+  // mutices can only be relased on the same thread as they are
+  // acquired on.
   mutex.acquire ();
   deallog << "OK." << std::endl;
   spin_lock = 1;
+  mutex.release ();
   return 42;
 }
 
@@ -60,11 +66,12 @@ int main()
   for (unsigned int i=0; i<sz; ++i)
     p[i] = 0;
 
+  // make sure the worker thread can actually start
   mutex.release ();
 
+  // wait for the worker thread to do its work
   while (spin_lock == 0)
     ;
-  mutex.release ();
 
   for (unsigned int i=0; i<sz; ++i)
     Assert (p[i] == 0, ExcInternalError());

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.