summaryrefslogtreecommitdiffstats
path: root/src/userprog/process.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/userprog/process.c')
-rw-r--r--src/userprog/process.c19
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