home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_11 / 8n11067a < prev    next >
Text File  |  1990-07-27  |  1KB  |  76 lines

  1. // suuser.cpp - Start Up User Tasks 
  2. //              Copyright 1990 by Cnapse
  3. //              Written by: M. de Champlain
  4.  
  5.  
  6. #include <stdio.h>
  7. #include "npx.hpp"
  8.  
  9. void Background(void)
  10.     {
  11.     printf("[%x]\tBackground started.\n", running->Self());
  12.     loop
  13.         {
  14.         running->ReSchedule();
  15.         putchar('.');
  16.         }
  17.     }
  18.  
  19. void Task0(void)
  20.     {
  21.     short n;
  22.  
  23.     printf("[%x]\tTask0 started.\n", running->Self());
  24.  
  25.     n = 10;
  26.     while (n--)
  27.         {
  28.         running->ReSchedule();
  29.         putchar('0');
  30.         }
  31.  
  32.     running->Terminate(running);
  33.     }
  34.  
  35. void Task1(void)
  36.     {
  37.     printf("[%x]\tTask1 started.\n", running->Self());
  38.     loop
  39.         {
  40.         running->ReSchedule();
  41.         putchar('1');
  42.         }
  43.     }
  44.  
  45. void StartUpUserTasks(void)
  46.     {
  47.     short  n;
  48.     Task  *t0, *t1;
  49.  
  50.     printf("[%x]\tStartUpUserTasks started.\n", running->Self());
  51.     (new Task(Background, 1024))->Start();
  52.     (t0 = new Task(     Task0, 1024))->Start();
  53.     (t1 = new Task(     Task1, 1024))->Start();
  54.  
  55.     n = 20;
  56.     while (n--)
  57.         {
  58.         running->ReSchedule();
  59.         putchar('S');
  60.         }
  61.  
  62.     running->Suspend(t1);
  63.  
  64.     n = 5;
  65.     while (n--)
  66.         {
  67.         running->ReSchedule();
  68.         putchar('S');
  69.         }
  70.  
  71.     running->Resume(t1);
  72.  
  73.     (new Task(Task0, 1024))->Start();
  74.     running->Terminate(running);
  75.     }
  76.