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