Update license section.
[pintos-anon] / grading / threads / join-quick.c
1 /* Problem 1-2: Join tests.
2
3    Based on a test originally submitted for Stanford's CS 140 in
4    winter 1998 by Rob Baesman <rbaesman@cs.stanford.edu>, Ben
5    Taskar <btaskar@cs.stanford.edu>, and Toli Kuznets
6    <tolik@cs.stanford.edu>.  Later modified by shiangc, yph, and
7    arens. */
8 #include "threads/test.h"
9 #include <stdio.h>
10 #include "threads/interrupt.h"
11 #include "threads/thread.h"
12
13 static void quick_test (void);
14
15 void
16 test (void) 
17 {
18   quick_test ();
19 }
20
21 static thread_func quick_thread_func;
22 static thread_func simple_thread_func;
23
24 static void
25 quick_test (void) 
26 {
27   tid_t tid2;
28   
29   printf ("\n"
30           "Testing quick join.\n"
31           "Thread 2 should finish before thread 3 starts.\n");
32
33   tid2 = thread_create ("2", PRI_DEFAULT, quick_thread_func, "2");
34   thread_yield ();
35   thread_join (tid2);
36   simple_thread_func ("3");
37   printf ("Quick join test done.\n");
38 }
39
40 void 
41 quick_thread_func (void *name_) 
42 {
43   const char *name = name_;
44   int i;
45
46   for (i = 0; i < 5; i++) 
47     {
48       printf ("Thread %s iteration %d\n", name, i);
49       thread_yield ();
50     }
51   printf ("Thread %s done!\n", name);
52 }
53
54 void 
55 simple_thread_func (void *name_) 
56 {
57   const char *name = name_;
58   int i;
59   
60   for (i = 0; i < 5; i++) 
61     {
62       printf ("Thread %s iteration %d\n", name, i);
63       thread_yield ();
64     }
65   printf ("Thread %s done!\n", name);
66 }