Update license section.
[pintos-anon] / grading / threads / join-dummy.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 dummy_test (void);
14
15 void
16 test (void) 
17 {
18   dummy_test ();
19 }
20
21 static thread_func simple_thread_func;
22
23 static void
24 dummy_test (void) 
25 {
26   tid_t tid0;
27   
28   printf ("\n"
29           "Testing dummy join.\n"
30           "Thread 0 should finish before thread 1 starts.\n");
31   tid0 = thread_create ("0", PRI_DEFAULT, simple_thread_func, "0");
32   thread_yield ();
33   thread_join (tid0);
34   thread_join (tid0);
35   simple_thread_func ("1");
36   thread_join (tid0);
37   printf ("Dummy join test done.\n");
38 }
39
40 void 
41 simple_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 }