X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=grading%2Fthreads%2Fjoin-quick.c;fp=grading%2Fthreads%2Fjoin-quick.c;h=78f1e3f71c9b4cdaa8b3552c7a0b398baf2438fc;hb=db1421e7321efc7bb3aa3b232fbde94ce154dd23;hp=0000000000000000000000000000000000000000;hpb=35b97d0503d2531ae4b3da93e176d394b87c2856;p=pintos-anon diff --git a/grading/threads/join-quick.c b/grading/threads/join-quick.c new file mode 100644 index 0000000..78f1e3f --- /dev/null +++ b/grading/threads/join-quick.c @@ -0,0 +1,68 @@ +/* Problem 1-2: Join tests. + + Based on a test originally submitted for Stanford's CS 140 in + winter 1998 by Rob Baesman , Ben + Taskar , and Toli Kuznets + . Later modified by shiangc, yph, and + arens. */ +#include "threads/test.h" +#include +#include "threads/interrupt.h" +#include "threads/thread.h" + +static void quick_test (void); + +void +test (void) +{ + quick_test (); +} + +static thread_func quick_thread_func; +static thread_func simple_thread_func; + +static void +quick_test (void) +{ + tid_t tid2; + + printf ("\n" + "Testing quick join.\n" + "Thread 2 should finish before thread 3 starts.\n"); + + tid2 = thread_create ("2", PRI_DEFAULT, quick_thread_func, "2"); + thread_yield (); + thread_join (tid2); + simple_thread_func ("3"); + printf ("Quick join test done.\n"); +} + +void +quick_thread_func (void *name_) +{ + const char *name = name_; + int i; + + intr_disable (); + + for (i = 0; i < 5; i++) + { + printf ("Thread %s iteration %d\n", name, i); + thread_yield (); + } + printf ("Thread %s done!\n", name); +} + +void +simple_thread_func (void *name_) +{ + const char *name = name_; + int i; + + for (i = 0; i < 5; i++) + { + printf ("Thread %s iteration %d\n", name, i); + thread_yield (); + } + printf ("Thread %s done!\n", name); +}