home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PP0706.ZIP / QUADRANT.C < prev   
C/C++ Source or Header  |  1988-03-29  |  3KB  |  93 lines

  1. /*--------------------------------------------------------------------------
  2.    QUADRANT.C -- OS/2 Program that Runs 4 Threads Using One Thread Function
  3.                  (C) 1988, Ziff-Davis Communications Company
  4.                  PC Magazine * Programmed by Charles Petzold, 11/87
  5.   --------------------------------------------------------------------------*/
  6.  
  7. #include <doscalls.h>
  8. #include <subcalls.h>
  9.  
  10. #define min(a,b) ((a) < (b) ? (a) : (b)) 
  11.  
  12. void far ThreadFunction (void) ;
  13.  
  14. main ()
  15.      {
  16.      static unsigned char ThreadStack [4][1024] ;
  17.      unsigned int         i, ThreadID [4] ;     struct KeyData       kd ;
  18.  
  19.      for (i = 0 ; i < 4 ; i++)
  20.           if (DOSCREATETHREAD (ThreadFunction, &ThreadID [i],
  21.                                ThreadStack [i] + 1024))
  22.                {
  23.                puts ("QUADRANT: Could not create thread") ;
  24.                return 1 ;
  25.                }
  26.  
  27.      KBDCHARIN (&kd, 0, 0) ;
  28.  
  29.      return 0 ;
  30.      }
  31.  
  32. #pragma check_stack-
  33.  
  34. void far ThreadFunction ()
  35.      {
  36.      static struct ModeData md ;
  37.      static int             ThreadNumber = 0, NumRep ;
  38.      unsigned int           MinRow, MaxRow, MinCol, MaxCol ;
  39.      unsigned int           MyThreadNum, Cycle, Rep, Row, Col ;
  40.  
  41.      DOSENTERCRITSEC () ;
  42.  
  43.      if (ThreadNumber == 0)
  44.           {
  45.           md.length = sizeof (md) ;
  46.           VIOGETMODE (&md, 0) ;
  47.  
  48.           NumRep = (min (md.col, md.row) / 2 + 1) / 2 ;
  49.           }
  50.  
  51.      MyThreadNum = ThreadNumber ;
  52.  
  53.      ThreadNumber += 1 ;
  54.  
  55.      DOSEXITCRITSEC () ;
  56.  
  57.      MinRow = MyThreadNum > 1 ? md.row / 2 : 0 ;
  58.      MaxRow = MinRow + md.row / 2 ;
  59.      MinCol = MyThreadNum % 2 ? md.col / 2 : 0 ;
  60.      MaxCol = MinCol + md.col / 2 ; 
  61.  
  62.      while (1)
  63.           for (Cycle = 0 ; Cycle < 2 ; Cycle++)
  64.                for (Rep = 0 ; Rep < NumRep ; Rep++)
  65.                     {
  66.                     Row = MinRow + Rep ;
  67.  
  68.                     for (Col = MinCol+Rep ; Col < MaxCol-Rep-1 ; Col++)
  69.                          Display (Cycle, Row, Col, MyThreadNum) ;
  70.                     for (Row = MinRow+Rep ; Row < MaxRow-Rep-1 ; Row++)
  71.                          Display (Cycle, Row, Col, MyThreadNum) ;
  72.  
  73.                     for (Col = MaxCol-Rep-1 ; Col > MinCol+Rep ; Col--)
  74.                          Display (Cycle, Row, Col, MyThreadNum)  ;
  75.  
  76.                     for (Row = MaxRow-Rep-1 ; Row > MinRow+Rep ; Row--)
  77.                          Display (Cycle, Row, Col, MyThreadNum) ;
  78.                     }
  79.      }
  80.  
  81. Display (Cycle, Row, Col, Num)
  82.      int Cycle, Row, Col, Num ;
  83.      {
  84.      char String [2] ;
  85.  
  86.      String [0] = (char) (Cycle == 0 ? Num + '0' : ' ') ;
  87.      String [1] = '\x07' ;
  88.  
  89.      VIOWRTCELLSTR (String, 2, Row, Col, 0) ;
  90.  
  91.      DOSSLEEP (0L) ;
  92.      }
  93.