diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-02-21 19:34:05 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-02-21 19:34:05 +0100 |
| commit | bd53394e2e05bf7897574f55ab6f88f7bcc2e258 (patch) | |
| tree | 4e32c40efa6647d7866a35e0bf8408a39b70a079 /src | |
| parent | 542bba093edc31ba41a8abd8dca95d14f1488fc0 (diff) | |
| download | pintos-bd53394e2e05bf7897574f55ab6f88f7bcc2e258.tar.gz | |
parent waits for child to start
Diffstat (limited to 'src')
| -rw-r--r-- | src/userprog/process.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/userprog/process.c b/src/userprog/process.c index c0a770b..437d6c0 100644 --- a/src/userprog/process.c +++ b/src/userprog/process.c @@ -15,11 +15,15 @@ #include "threads/init.h" #include "threads/interrupt.h" #include "threads/palloc.h" +#include "threads/synch.h" #include "threads/thread.h" #include "threads/vaddr.h" struct start_process_args { + struct semaphore sema; + + // parent -> child char *file_name; }; @@ -38,7 +42,7 @@ process_execute (const char *file_name) printf("%s starting %s\n", thread_current ()->name, file_name); - sema_init (&args.sema); + sema_init (&args.sema, 0); /* Make a copy of FILE_NAME. Otherwise there's a race between the caller and load(). */ @@ -54,13 +58,10 @@ process_execute (const char *file_name) wait for the child to signal that it has read the args. Only then can we free resources and return the tid. */ tid = thread_create (file_name, PRI_DEFAULT, start_process, &args); - if (tid == TID_ERROR) { - palloc_free_page (args.file_name); - } else { - //TODO thread created, wait to see if start_process worked - // return -1 if failed + if (tid != TID_ERROR) { + sema_down (&args.sema); } - printf("woops\n"); + palloc_free_page (args.file_name); return tid; } @@ -81,14 +82,16 @@ start_process (void *args_) printf("reading\n"); success = load (args->file_name, &if_.eip, &if_.esp); + sema_up (&args->sema); + /* If load failed, quit. */ - palloc_free_page (args->file_name); if (success) { //TODO report success } else { //TODO report failure thread_exit (); } + /* Start the user process by simulating a return from an interrupt, implemented by intr_exit (in threads/intr-stubs.S). Because intr_exit takes all of its |
