From ddcd59fdf8a744cc2b19b1d43e78b300e67320b3 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Fri, 8 Nov 2024 02:52:38 +0000 Subject: [PATCH] Add child and own process result information to struct thread --- src/threads/thread.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/threads/thread.h b/src/threads/thread.h index 1c05030..cf35b82 100644 --- a/src/threads/thread.h +++ b/src/threads/thread.h @@ -4,6 +4,8 @@ #include #include #include +#include +#include "threads/synch.h" #include "threads/fixed-point.h" /* States in a thread's life cycle. */ @@ -29,6 +31,19 @@ typedef int tid_t; #define NICE_DEFAULT 0 /* Default niceness. */ #define NICE_MAX 20 /* Highest niceness. */ +/* 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 0 when parent dies, or to exit_status when + child dies (whichever happens first). */ + struct lock lock; /* Lock to synchronise access to the exit_status. */ + 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. */ +}; + /* A kernel thread or user process. Each thread structure is stored in its own 4 kB page. The @@ -108,6 +123,11 @@ struct thread int nice; /* Nice value for this thread */ fp32_t recent_cpu; /* Amount of time this process received */ + /* Process wait properties. */ + struct process_result *result; /* Result of the process. */ + struct list child_results; /* List of children's of this thread + process results. */ + /* Shared between thread.c and synch.c. */ struct list_elem elem; /* List element. */