Fix process_result locking by acquiring in process_wait as well to prevent freeing memory too early

This commit is contained in:
2024-11-08 10:50:10 +00:00
parent 84fe637c7e
commit 6ed1ccd21e
3 changed files with 28 additions and 7 deletions

View File

@@ -647,6 +647,7 @@ 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;
}

View File

@@ -34,9 +34,10 @@ typedef int tid_t;
/* A process result, synchronised between parent and child. */
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. */
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 the exit_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. */