]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Try more.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 3 Oct 2002 23:47:19 +0000 (23:47 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 3 Oct 2002 23:47:19 +0000 (23:47 +0000)
git-svn-id: https://svn.dealii.org/trunk@6607 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/contrib/hsl/source/detached_ma27.cc
deal.II/lac/source/sparse_direct.cc

index 9fa3f15aea3e92ef3d624b0cd071159523fd872f..f0f86a88369e507513131874619155ac071cb04d 100644 (file)
@@ -218,9 +218,9 @@ int main ()
                                    // ...and start off a thread that
                                    // actually checks that
   Threads::ThreadManager thread_manager;
-  Threads::spawn (thread_manager,
-                  Threads::encapsulate (&monitor_parent_liveness)
-                  .collect_args(master_pid, getpid()));
+//   Threads::spawn (thread_manager,
+//                   Threads::encapsulate (&monitor_parent_liveness)
+//                   .collect_args(master_pid, getpid()));
   
                                    // then go into the action loop...
   unsigned int N, NZ, NSTEPS, LA, MAXFRT, LIW;
index a337a1aff2e71214cd682d1c20512041f7bf0230..05ee294eb0dc1a951aef470e18e086c5797c5bc3 100644 (file)
@@ -312,27 +312,68 @@ void die (const std::string &text, const T1 t1, const T2 t2, const pid_t child)
  * process is dead but still exists, so kill will not report an error. so
  * we have to make sure we call wait* before the kill, but then we also 
  * do not want to use a blocking wait, so use it with WNOHANG
+ *
+ * the reason we check at all is that if the child dies and we do not
+ * eventually kill the master as well, we may end up in a situation
+ * where the master is waiting indefinitely for incoming data. so
+ * rather than creating a situation where the master hangs, we'd like
+ * to abort it
  */
-void monitor_child_liveness (const pid_t child_pid) 
+namespace MonitorChildLiveness 
 {
-  while (true)
-    {
-      waitpid (child_pid, 0, WNOHANG);
-      int ret = kill (child_pid, 0);
-      if (ret != 0)
-        if ((ret == -1) && (errno == ESRCH))
-          die ("Child process seems to have died!", child_pid);
-        else
-          die ("Unspecified error while checking for other process!", ret, errno, child_pid);
-
-                                       // ok, master still running,
-                                       // take a little rest and then
-                                       // ask again
-      sleep (10);
-    };
+  Threads::ThreadMutex process_list_lock;
+  std::list<pid_t> process_list;
+  
+  void monitor (const pid_t child_pid) 
+  {
+    while (true)
+      {
+                                         // check whether the process
+                                         // we are looking for is
+                                         // still in the list of
+                                         // pending processes
+        process_list_lock.acquire ();
+        bool process_found = false;
+        for (std::list<pid_t>::const_iterator i=process_list.begin();
+             i!=process_list.end(); ++i)
+          if (*i == child_pid)
+            {
+              process_found = true;
+              break;
+            };
+        process_list_lock.release ();
+        
+                                         // if not, then the
+                                         // respective process has
+                                         // exited gracefully upon our
+                                         // request, and has been
+                                         // deleted from the
+                                         // list. then we can exit
+                                         // this monitor thread
+        if (process_found == false)
+          return;
+
+                                         // otherwise, we expect the
+                                         // process to still be
+                                         // living. check this:
+        waitpid (child_pid, 0, WNOHANG);
+        int ret = kill (child_pid, 0);
+        if (ret != 0)
+          if ((ret == -1) && (errno == ESRCH))
+            die ("Child process seems to have died!", child_pid);
+          else
+            die ("Unspecified error while checking for other process!", ret, errno, child_pid);
+        
+                                         // ok, master still running,
+                                         // take a little rest and then
+                                         // ask again
+        sleep (10);
+      };
+  };
 };
 
 
+
 Threads::ThreadManager child_liveness_watchers;
 
 
@@ -448,8 +489,24 @@ SparseDirectMA27::~SparseDirectMA27()
   if (detached_mode)
     if (detached_mode_data != 0)
       {
+                                         // first remove this process
+                                         // from the watch list. this
+                                         // will also terminate the
+                                         // watcher thread on its next
+                                         // awakening
+      MonitorChildLiveness::process_list_lock.acquire();
+      for (std::list<pid_t>::iterator
+             i=MonitorChildLiveness::process_list.begin();
+           i!=MonitorChildLiveness::process_list.end(); ++i)
+        if (*i == detached_mode_data->child_pid)
+          {
+            MonitorChildLiveness::process_list.erase (i);
+            break;
+          };
+      MonitorChildLiveness::process_list_lock.release();
+        
 
-                                         // first close down client
+                                         // next close down client
         detached_mode_data->mutex.acquire ();
         write (detached_mode_data->server_client_pipe[1], "7", 1);
         detached_mode_data->mutex.release ();
@@ -550,9 +607,15 @@ SparseDirectMA27::initialize (const SparsityPattern &sp)
       const pid_t parent_pid = getpid();
       detached_mode_data->put (&parent_pid, 1, "parent_pid");
 
-      Threads::spawn (child_liveness_watchers,
-                      Threads::encapsulate(&monitor_child_liveness)
-                      .collect_args (detached_mode_data->child_pid));
+                                       // then set up a watcher thread
+      MonitorChildLiveness::process_list_lock.acquire();
+      MonitorChildLiveness::
+        process_list.push_back (detached_mode_data->child_pid);
+      MonitorChildLiveness::process_list_lock.release();
+      
+//       Threads::spawn (child_liveness_watchers,
+//                       Threads::encapsulate(&MonitorChildLiveness::monitor)
+//                       .collect_args (detached_mode_data->child_pid));
     };
   
   

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.