00001 #include <j2k/Fred/Standard.hpp>
00002 #include <j2k/Fred/Error/JError.cpp>
00003 #include <j2k/445/Posix/PThread.cpp>
00004
00005
00006
00007 #define MAX 10000
00008
00009 Mutex ml;
00010 int p = 100;
00011
00012 class Fred : public PThread
00013 {
00014 public:
00015 Fred( char* n = ".", int a = 0 ) : PThread(), s( n ), amount( a ) { }
00016
00017 virtual void run() {
00018 for(;;) {
00019 printf(",");
00020 ml.lock();
00021 printf("[");
00022 printf("%s", s);
00023 printf("]");
00024 ml.unlock();
00025 printf(",");
00026 sched_yield();
00027 }
00028 }
00029
00030 char* s;
00031 int amount;
00032 };
00033
00034 class Fred2 : public PThread
00035 {
00036 public:
00037 Fred2( char* n = ".", int a = 0 ) : PThread(), s( n ), amount( a ) { }
00038
00039 virtual void run() {
00040 for(;;) {
00041 printf(",");
00042 ml.lock();
00043 printf("(");
00044 printf("%s", s);
00045 printf(")");
00046 ml.unlock();
00047 printf(",");
00048 sched_yield();
00049 }
00050 }
00051
00052 char* s;
00053 int amount;
00054 };
00055
00056
00057 int main( int argc = 0, char* argv[] = NULL)
00058 {
00059 Fred* t1 = new Fred( "0", 10 );
00060 Fred2* t2 = new Fred2( "1", -20 );
00061
00062 PThread* t = NULL;
00063
00064 t = t1;
00065 cout << "t1->start();\n";
00066 t1->start();
00067
00068 t = t2;
00069 cout << "t2->start();\n";
00070 t2->start();
00071
00072 int max = MAX;
00073
00074 if ( argc ) {
00075 printf("max = %s", argv[1] );
00076 max = atoi( argv[1] );
00077 if ( max < 10 ) max = MAX;
00078 }
00079
00080 for( int i = 0; i < max; i++ ) {
00081 cout << ".";
00082 }
00083
00084 return 0;
00085 }