Update license section.
[pintos-anon] / grading / threads / join-simple.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 simple_test (void);
14
15 void
16 test (void) 
17 {
18   simple_test ();
19 }
20
21 static thread_func simple_thread_func;
22
23 static void
24 simple_test (void) 
25 {
26   tid_t tid0;
27   
28   printf ("\n"
29           "Testing simple 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   simple_thread_func ("1");
35   printf ("Simple join test done.\n");
36 }
37
38 void 
39 simple_thread_func (void *name_) 
40 {
41   const char *name = name_;
42   int i;
43   
44   for (i = 0; i < 5; i++) 
45     {
46       printf ("Thread %s iteration %d\n", name, i);
47       thread_yield ();
48     }
49   printf ("Thread %s done!\n", name);
50 }