Преглед изворни кода

[LibOS] Instruct thread_exit() to send IPC_CLD_EXIT only once

Previously, when a thread exited via thread_exit(), it could send two
identical IPC_CLD_EXIT messages under certain conditions. This commit
fixes this bug and forces thread_exit() to send IPC_CLD_EXIT at most once.
Dmitrii Kuvaiskii пре 6 година
родитељ
комит
61be1b2e40
1 измењених фајлова са 6 додато и 2 уклоњено
  1. 6 2
      LibOS/shim/src/sys/shim_exit.c

+ 6 - 2
LibOS/shim/src/sys/shim_exit.c

@@ -44,10 +44,14 @@ void release_clear_child_id (int * clear_child_tid);
 
 int thread_exit(struct shim_thread * self, bool send_ipc)
 {
+    bool sent_exit_msg = false;
+
     /* Chia-Che: Broadcast exit message as early as possible,
        so other process can start early on responding. */
-    if (self->in_vm && send_ipc)
+    if (self->in_vm && send_ipc) {
         ipc_cld_exit_send(self->ppid, self->tid, self->exit_code, self->term_signal);
+        sent_exit_msg = true;
+    }
 
     lock(&self->lock);
 
@@ -99,7 +103,7 @@ int thread_exit(struct shim_thread * self, bool send_ipc)
         unlock(&parent->lock);
 
         DkEventSet(parent->child_exit_event);
-    } else {
+    } else if (!sent_exit_msg) {
         debug("parent not here, need to tell another process\n");
         ipc_cld_exit_send(self->ppid, self->tid, self->exit_code, self->term_signal);
     }