Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/Deprecated/old_18mar_diff/nto/Basic_Test.cpp

Go to the documentation of this file.
00001 #ifndef __J2K__Basic_Test_CPP__
00002 #define __J2K__Basic_Test_CPP__
00003 
00004 
00005 #include <j2k/Fred/Standard.hpp>
00006 #include <j2k/nto/Basic_PThread.hpp>
00007 #include <j2k/nto/Mutex.hpp>
00008 
00009 /*
00010  * Objectives:
00011  *   - See if each thread runs or get enough CPU time
00012  *   - See the behavior of the scheduler
00013  *
00014  * Display:
00015  *   111111111111   ( Thread 1 running )
00016  *   222222222222   ( Thread 2 running )
00017  *   333333333333   ( Thread 3 running )
00018  *   444444444444   ( Thread 4 running )
00019  *   555555555555   ( Thread 5 running )
00020  *   ............   ( Parent   running, i.e. the main() { } )
00021  *
00022  */
00023 
00024 
00025 #define MAX  100
00026 
00027 Mutex ml;
00028 int p = 100;
00029 
00030 class Fred : public Basic_PThread 
00031 {
00032 public:
00033    Fred( char* n = ".", int a = 0 ) : Basic_PThread(), s( n ) { } 
00034 
00035    virtual void run() {
00036      for(;;) {
00037    for( int i = 0; i < 10; i++ ) {
00038            ml.lock();
00039            printf("%s", s);
00040       ml.unlock();
00041         }
00042      
00043         sched_yield();
00044      }
00045    } 
00046 
00047    char* s;
00048    int   amount;
00049 };
00050 
00051 int main( int argc = 0, char* argv[] = NULL) 
00052 {
00053   Fred*  t1 = new Fred( "1",  10 );
00054   Fred*  t2 = new Fred( "2", -20 );
00055   Fred*  t3 = new Fred( "3", -20 );
00056   Fred*  t4 = new Fred( "4", -20 );
00057   Fred*  t5 = new Fred( "5", -20 );
00058 
00059   t1->start();
00060   t2->start();
00061   t3->start();
00062   t4->start();
00063   t5->start();
00064 
00065   t1->join();
00066   t2->join();
00067   t3->join();
00068   t4->join();
00069   t5->join();
00070 
00071   printf("t1-5 started.\n\n");
00072 
00073   int max = MAX;
00074 
00075   setprio( 0, getprio( 0 ) - 1 );
00076 
00077   for( int i = 0; i < max; i++ ) { 
00078    printf( "." );
00079    sched_yield();
00080   }
00081 
00082   return 0;
00083 }
00084 
00085 #endif

Generated on Sun Oct 14 18:46:21 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001