From 84fe637c7e284dd8dab7e2a7ce036857900e1926 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Fri, 8 Nov 2024 09:16:18 +0000 Subject: [PATCH] Remove process_result lock since it is an invalid solution TODO : synchronise process_result in another way --- src/threads/thread.c | 1 - src/threads/thread.h | 1 - src/userprog/process.c | 22 ++++------------------ 3 files changed, 4 insertions(+), 20 deletions(-) diff --git a/src/threads/thread.c b/src/threads/thread.c index 379894d..aecafdf 100644 --- a/src/threads/thread.c +++ b/src/threads/thread.c @@ -647,7 +647,6 @@ init_process_result (struct thread *t) struct process_result *result = malloc (sizeof (struct process_result)); result->tid = t->tid; result->exit_status = t->exit_status; - lock_init (&result->lock); sema_init (&result->sema, 0); t->result = result; } diff --git a/src/threads/thread.h b/src/threads/thread.h index 6465d53..f6227f5 100644 --- a/src/threads/thread.h +++ b/src/threads/thread.h @@ -37,7 +37,6 @@ struct process_result tid_t tid; /* The tid of the child process. */ int exit_status; /* The exit status of the child process. Initially set to -1, then to exit_status when child dies. */ - struct lock lock; /* Lock to synchronise access to the status and sema. */ struct semaphore sema; /* Semaphore to signal the parent that the exit_status has been set. */ struct list_elem elem; /* List element for the parent's children list. */ diff --git a/src/userprog/process.c b/src/userprog/process.c index 5b41a34..1db334a 100644 --- a/src/userprog/process.c +++ b/src/userprog/process.c @@ -245,21 +245,14 @@ process_exit (void) /* Update process result. */ if (cur->result != NULL) { - lock_acquire (&cur->result->lock); cur->result->exit_status = cur->exit_status; /* Parent has died, child has to free the struct process_result * */ if (sema_try_down (&cur->result->sema)) - { - lock_release (&cur->result->lock); - free (cur->result); - } + free (cur->result); /* Parent is still alive and will be the one to free the struct process_result *, and may be waiting so call sema_up */ else - { - sema_up (&cur->result->sema); - lock_release (&cur->result->lock); - } + sema_up (&cur->result->sema); } struct list_elem *e; @@ -268,19 +261,12 @@ process_exit (void) { struct process_result *result = list_entry (e, struct process_result, elem); - lock_acquire (&result->lock); /* Child has died (and was not waited for). Free the result. */ if (sema_try_down (&result->sema)) - { - lock_release (&result->lock); - free (result); - } + free (result); /* Child is still alive, signal via sema that parent has died. */ else - { - sema_up (&result->sema); - lock_release (&result->lock); - } + sema_up (&result->sema); } /* Destroy the current process's page directory and switch back