Use a single exit_status instead of two

This commit is contained in:
2024-11-15 17:20:51 +00:00
parent e76712d3fd
commit 8567434231
4 changed files with 12 additions and 21 deletions

View File

@@ -56,7 +56,7 @@ struct process_start_data
};
static thread_func start_process NO_RETURN;
static void destruct_process_result (struct hash_elem *e, void *aux);
static void destruct_process_result (struct hash_elem *e, void *aux UNUSED);
static bool load (const char *cmdline, void (**eip) (void), void **esp);
/* Starts a new thread running a user program executed via
@@ -355,8 +355,6 @@ process_exit (void)
struct thread *cur = thread_current ();
uint32_t *pd;
printf ("%s: exit(%d)\n", cur->name, cur->exit_status);
/* Clean up all open files */
hash_destroy (&cur->open_files, fd_cleanup);
@@ -369,9 +367,12 @@ process_exit (void)
lock_release (&filesys_lock);
}
/* Update own process result. */
if (cur->result != NULL)
destruct_process_result (&cur->result->elem, cur);
{
printf ("%s: exit(%d)\n", cur->name, cur->result->exit_status);
/* Update own process result. */
destruct_process_result (&cur->result->elem, cur);
}
/* Free child process results or signal parent's death. */
hash_destroy (&cur->child_results, destruct_process_result);
@@ -394,16 +395,12 @@ process_exit (void)
}
}
/* Destruct a process_result, with multi-thread awareness. Takes the
process_result->elem and current thread.
/* Destruct a process_result, with multi-thread awareness.
If the other thread is running, simply signals death. Otherwise
frees the result.
Also set's process_result->exit_status if the process result is FOR
the current thread. */
frees the result. */
static void
destruct_process_result (struct hash_elem *e, void *cur_)
destruct_process_result (struct hash_elem *e, void *aux UNUSED)
{
struct thread *cur = cur_;
struct process_result *result = hash_entry (e, struct process_result, elem);
lock_acquire (&result->lock);
/* Other thread has died (and was not waited for). Free the result. */
@@ -415,8 +412,6 @@ destruct_process_result (struct hash_elem *e, void *cur_)
/* Other thread is still alive, signal via sema that parent has died. */
else
{
if (cur->tid == result->tid)
result->exit_status = cur->exit_status;
sema_up (&result->sema);
lock_release (&result->lock);
}