home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Samples / Critics / Source / Critics.cpp next >
C/C++ Source or Header  |  1996-08-12  |  2KB  |  102 lines

  1. // OCL Sample 
  2. // Critics.cpp
  3.  
  4. #define __OCL_RESOLVE_TEMPLATES__
  5. #include "..\Source\critics.hpp"
  6.  
  7. #if defined(__EMX__)
  8.   template class OThread<Thread>;
  9. #endif
  10.  
  11. USHORT         row;
  12.  
  13. void main(void)
  14. {
  15.  USHORT         col;   
  16.  Thread         first  ("First   :", 1);
  17.  Thread         second ("Second  :", 2);
  18.  Thread         third  ("Third   :", 3);
  19.  CriticalThread master (4);
  20.  
  21.  cout << "\n\n\n" << endl;
  22.  VioGetCurPos(&row, &col, 0);
  23.  row -= 4;
  24.  
  25.  try 
  26.    {
  27.     first.paint.run();
  28.     DosSleep(1000); 
  29.     second.paint.run();
  30.     DosSleep(1000); 
  31.     third.paint.run();
  32.     DosSleep(1000); 
  33.     master.paint.run();
  34.  
  35.     // wait for all threads
  36.     master.paint.waitFor();
  37.     first.paint.waitFor();
  38.     second.paint.waitFor();
  39.     third.paint.waitFor();
  40.    }
  41.  catch(OVioException& err)
  42.    {
  43.     err.viewError();
  44.    }
  45.  _exit(0);
  46. }
  47.  
  48.  
  49. // class implementation Thread
  50.  
  51. Thread::Thread(PSZ name, USHORT threadRow)
  52.   : paint(this, &Thread::paintfunc, USHRT_MAX, FALSE),
  53.     threadName(name),
  54.     line(threadRow),   
  55.     count(0)
  56.   {}
  57.  
  58. Thread::~Thread()
  59.   {}
  60.   
  61. PSZ Thread::isOfType() const
  62. {
  63.  return("Thread");
  64. }
  65.  
  66. void Thread::paintfunc()
  67. {
  68.  for(ULONG i = 0; i < 11; i++)
  69.   {
  70.    CHAR  str[40];
  71.  
  72.    sprintf(str, "%s %ld ticks.", threadName, i);
  73.    VioWrtCharStr(str, strlen(str), row + line, 0, 0);
  74.    DosSleep(1000);
  75.   }
  76. }
  77.  
  78.  
  79. // class implementation CriticalThread
  80.  
  81. CriticalThread::CriticalThread(USHORT threadRow)
  82.   : Thread("Critical:", threadRow) 
  83.   {}
  84.  
  85. CriticalThread::~CriticalThread()
  86.   {}
  87.    
  88. PSZ CriticalThread::isOfType() const
  89. {
  90.  return("CriticalThread");
  91. }
  92.  
  93. void CriticalThread::paintfunc()
  94. {
  95.  critical.enter();
  96.  Thread::paintfunc();
  97.  critical.exit();
  98. }
  99.  
  100.  
  101. // end of source 
  102.