00001
00002
00003
00004
00005
00006
00007
00008 #include <utility/ostream.h>
00009 #include <utility/malloc.h>
00010 #include <thread.h>
00011 #include <alarm.h>
00012
00013 __USING_SYS
00014
00015 const int iterations = 100;
00016
00017 int func_a(void);
00018 int func_b(void);
00019
00020 Thread * a;
00021 Thread * b;
00022 Thread * m;
00023
00024 OStream cout;
00025
00026 Select_Debug<false> x;
00027
00028 int main()
00029 {
00030 cout << "Thread test\n";
00031
00032
00033
00034
00035
00036
00037 a = new Thread(&func_a);
00038 b = new Thread(&func_b);
00039
00040
00041
00042 cout << "Both threads are now done and have suspended themselves. I'll now wake them up so they can exit ...\n";
00043
00044
00045
00046
00047 int status_a = a->join();
00048 int status_b = b->join();
00049
00050
00051
00052
00053
00054 cout << "Thread A exited with status " << status_a
00055 << " and thread B exited with status " << status_b << "\n";
00056
00057
00058
00059
00060
00061 cout << "I'm also done, bye!\n";
00062
00063 return 0;
00064 }
00065
00066 int func_a(void) {
00067 for(int i = iterations; i > 0; i--) {
00068 for(int i = 0; i < 79; i++)
00069 cout << "a";
00070 cout << "\n";
00071 Alarm::delay(1000000);
00072 }
00073
00074
00075
00076
00077 return 'A';
00078 }
00079
00080 int func_b(void) {
00081 for(int i = iterations; i > 0; i--) {
00082 for(int i = 0; i < 79; i++)
00083 cout << "b";
00084 cout << "\n";
00085 Alarm::delay(1000000);
00086 }
00087
00088
00089
00090
00091
00092
00093 return 'B';
00094 }