00001
00045 #include "myThread.h"
00046 #include <unistd.h>
00047 #include <fcntl.h>
00048
00049
00050 void delay ( void );
00051
00052
00053 void thread1 ( void );
00054 void thread2 ( void );
00055 void thread3 ( void );
00056 void thread4 ( void );
00057 void thread5 ( void );
00058
00059 int
00060 main ( int argc , char **argv )
00061 {
00062
00063 myThread_init();
00064
00065
00066 myThread_create ( thread1 );
00067 myThread_create ( thread2 );
00068
00069
00070 for ( ; ; ) {
00071 char message[] = "This is the Main Thread\n";
00072 write ( STDOUT_FILENO , message , sizeof ( message ) );
00073 delay();
00074 }
00075
00076
00077 for ( ;; )
00078 ;
00079
00080 return 0;
00081 }
00082
00083
00084 void thread1 ( void )
00085 {
00086
00087 myThread_create ( thread3 );
00088
00089
00090 for ( int i = 1 ; i <= 10 ; ++i ) {
00091 char message[] = "This is Thread 1\n";
00092 write ( STDOUT_FILENO , message , sizeof ( message ) );
00093 delay();
00094 }
00095
00096
00097 myThread_exit ( 0 );
00098 }
00099
00100
00101 void thread2 ( void )
00102 {
00103
00104 myThread_create ( thread4 );
00105
00106
00107 for ( ; ; ) {
00108 char message[] = "This is Thread 2\n";
00109 write ( STDOUT_FILENO , message , sizeof ( message ) );
00110 delay();
00111 }
00112
00113
00114 myThread_exit ( 0 );
00115 }
00116
00117
00118 void thread3 ( void )
00119 {
00120
00121 myThread_create ( thread5 );
00122
00123
00124 for ( ; ; ) {
00125 char message[] = "This is Thread 3\n";
00126 write ( STDOUT_FILENO , message , sizeof ( message ) );
00127 delay();
00128 }
00129
00130
00131 myThread_exit ( 0 );
00132 }
00133
00134
00135 void thread4 ( void )
00136 {
00137
00138 for ( int i = 1 ; i <= 5 ; ++i ) {
00139 char message[] = "This is Thread 4\n";
00140 write ( STDOUT_FILENO , message , sizeof ( message ) );
00141 delay();
00142 }
00143
00144
00145 myThread_exit ( 0 );
00146 }
00147
00148
00149 void thread5 ( void )
00150 {
00151
00152 for ( ; ; ) {
00153 char message[] = "This is Thread 5\n";
00154 write ( STDOUT_FILENO , message , sizeof ( message ) );
00155 delay();
00156 }
00157
00158
00159 myThread_exit ( 0 );
00160 }
00161
00162
00163 void delay ( void )
00164 {
00165 for ( int i = 0 ; i < 10000 ; ++i )
00166 for ( int i = 0 ; i < 10000 ; ++i )
00167 ;
00168 }