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

C:/temp/src/j2k/nto/bakJuly/MsgThreadTest.cpp

Go to the documentation of this file.
00001 #include <j2k/Fred/Standard.hpp>
00002 #include <j2k/nto/Message.hpp>
00003 #include <j2k/nto/Namespace.hpp>
00004 #include <j2k/nto/MsgThread.hpp>
00005 
00006 #include <j2k/nto/TimerPulse.hpp>
00007 
00008 #include <j2k/nto/Basic_PThread.cpp>
00009 #include <j2k/nto/Message.cpp>
00010 #include <j2k/nto/Namespace.cpp>
00011 #include <j2k/nto/MsgThread.cpp>
00012 
00013 #include <j2k/nto/TimerPulse.cpp>
00014 
00015 class TimerPulseTest : public TimerPulse {
00016 public:
00017 
00018  TimerPulseTest( ULONG clk = WAITING )
00019   : TimerPulse( clk ), loop( 0 ), avg( 0 ) 
00020  { 
00021  }
00022 
00023  virtual void tick( int signo )
00024  {
00025     loop++;
00026     printf( "#" );
00027     fflush( stdout );
00028     if ( loop > 100 )
00029     {
00030       exit( 0 );
00031     }
00032  }
00033 
00034  int loop;
00035  virtual ~TimerPulseTest() { }
00036 };
00037 
00038 class Client : public MsgThread
00039 {
00040 public:
00041 
00042   int id;
00043   pid_t p;
00044 
00045   Client( MsgNameSpace* n0 ) : MsgThread( client, n0 ) 
00046   { 
00047     p = pid;
00048   }
00049 
00050   virtual void run()
00051   {
00052     printf( "Client start\n" );
00053     setprio( pid, 8 );
00054     sched_yield();
00055     int i = 20;
00056     while( i < 30 )
00057     {
00058       printf( "C[%d]", i );
00059       MsgThread::send( i++ );
00060     }
00061   }
00062 };
00063 
00064 class Server : public MsgThread
00065 {
00066 public:
00067   pid_t p;
00068   int   id;
00069 
00070   Server( MsgNameSpace* n0, const char* name ) : MsgThread( server, n0, name ) 
00071   { 
00072     p = pid;    
00073   }
00074 
00075   virtual void run()
00076   {
00077     printf( "Server start\n" );
00078     setprio( pid, 8 );
00079     sched_yield();
00080 
00081     int i = 10000;
00082     while( i < 10030 )
00083     {
00084       printf( "S" );
00085       int rcvid = MsgThread::receive();
00086 
00087       if ( rcvid == -1 ) break;
00088 
00089       int r = MsgThread::handleReceive( rcvid );
00090 
00091       if ( r != 0 ) continue;
00092 
00093       printf( "S[%d][%d]", m->getMessageNumber(), i );
00094 
00095       MsgThread::reply( rcvid, i++ );
00096     }
00097   }
00098 };
00099 
00100 int main()
00101 {
00102   MsgNameSpace* nn = new MsgNameSpace();
00103 
00104   Server a( nn, "fred" );
00105   Client b( nn );
00106 
00107   a.start();
00108   b.start();
00109 
00110   a.id = (int)b.p;
00111   b.id = (int)a.p;
00112 
00113   a.join();
00114   b.join();
00115 
00116   TimerPulseTest t;
00117   t.start();
00118 
00119   for( int k = 0; k < 100; k++ ) 
00120   { 
00121    printf( "M" );
00122    setprio( pthread_self(), 9 );
00123    sched_yield();
00124   } 
00125 
00126 return 0;
00127 }

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