Update license section.
[pintos-anon] / grading / threads / join-multiple.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 multiple_test (void);
14
15 void
16 test (void) 
17 {
18   multiple_test ();
19 }
20
21 static thread_func simple_thread_func;
22
23 static void
24 multiple_test (void) 
25 {
26   tid_t tid4, tid5;
27   
28   printf ("\n"
29           "Testing multiple join.\n"
30           "Threads 4 and 5 should finish before thread 6 starts.\n");
31
32   tid4 = thread_create ("4", PRI_DEFAULT, simple_thread_func, "4");
33   tid5 = thread_create ("5", PRI_DEFAULT, simple_thread_func, "5");
34   thread_yield ();
35   thread_join (tid4);
36   thread_join (tid5);
37   simple_thread_func ("6");
38   printf ("Multiple join test done.\n");
39 }
40
41 void 
42 simple_thread_func (void *name_) 
43 {
44   const char *name = name_;
45   int i;
46   
47   for (i = 0; i < 5; i++) 
48     {
49       printf ("Thread %s iteration %d\n", name, i);
50       thread_yield ();
51     }
52   printf ("Thread %s done!\n", name);
53 }