1 /* Problem 1-2: Join tests.
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
8 #include "threads/test.h"
10 #include "threads/interrupt.h"
11 #include "threads/thread.h"
13 static void simple_test (void);
14 static void quick_test (void);
15 static void multiple_test (void);
25 static thread_func simple_thread_func;
26 static thread_func quick_thread_func;
34 "Testing simple join.\n"
35 "Thread 0 should finish before thread 1 starts.\n");
36 tid0 = thread_create ("0", PRI_DEFAULT, simple_thread_func, "0");
39 simple_thread_func ("1");
40 printf ("Simple join test done.\n");
49 "Testing quick join.\n"
50 "Thread 2 should finish before thread 3 starts.\n");
52 tid2 = thread_create ("2", PRI_DEFAULT, quick_thread_func, "2");
55 simple_thread_func ("3");
56 printf ("Quick join test done.\n");
65 "Testing multiple join.\n"
66 "Threads 4 and 5 should finish before thread 6 starts.\n");
68 tid4 = thread_create ("4", PRI_DEFAULT, simple_thread_func, "4");
69 tid5 = thread_create ("5", PRI_DEFAULT, simple_thread_func, "5");
73 simple_thread_func ("6");
74 printf ("Multiple join test done.\n");
78 simple_thread_func (void *name_)
80 const char *name = name_;
83 for (i = 0; i < 5; i++)
85 printf ("Thread %s iteration %d\n", name, i);
88 printf ("Thread %s done!\n", name);
92 quick_thread_func (void *name_)
94 const char *name = name_;
99 for (i = 0; i < 5; i++)
101 printf ("Thread %s iteration %d\n", name, i);
104 printf ("Thread %s done!\n", name);