home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / TRSICAT.LZX / CATS_CD2_TRSI / Reference_Library / lib_examples / simpletask.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-21  |  1.9 KB  |  72 lines

  1. ;/* simpletask.c - Execute me to compile me with SAS C 5.10
  2. LC -b1 -cfistq -v -y -j73 simpletask.c
  3. Blink FROM LIB:c.o,simpletask.o TO simpletask LIBRARY LIB:LC.lib,LIB:Amiga.lib
  4. quit
  5.  
  6. simpletask.c - Uses the amiga.lib function CreateTask() to create a simple
  7. subtask.  See the Includes and Autodocs manual for CreateTask() source code
  8. */
  9. #include <exec/types.h>
  10. #include <exec/memory.h>
  11. #include <exec/tasks.h>
  12. #include <libraries/dos.h>
  13.  
  14. #include <clib/exec_protos.h>
  15. #include <clib/alib_protos.h>
  16.  
  17. #include <stdlib.h>
  18. #include <stdio.h>
  19.  
  20. #ifdef LATTICE
  21. int CXBRK(void) { return(0); }   /* Disable Lattice CTRL/C handling */
  22. int chkabort(void) {return(0);}
  23. #endif
  24.  
  25. #define STACK_SIZE 1000L
  26.  
  27. /* Task name, pointers for allocated task struct and stack */
  28. struct Task *task = NULL;
  29. char *simpletaskname = "SimpleTask";
  30.  
  31. ULONG sharedvar;
  32.  
  33. /* our function prototypes */
  34. void simpletask(void);
  35. void cleanexit(UBYTE *,LONG);
  36.  
  37. void main(int argc,char **argv)
  38. {
  39.     sharedvar = 0L;
  40.  
  41.     task = CreateTask(simpletaskname,0,simpletask,STACK_SIZE);
  42.     if(!task)  cleanexit("Can't create task",RETURN_FAIL);
  43.  
  44.     printf("This program initialized a variable to zero, then started a\n");
  45.     printf("separate task which is incrementing that variable right now,\n");
  46.     printf("while this program waits for you to press RETURN.\n");
  47.     printf("Press RETURN now: ");
  48.     getchar();
  49.  
  50.     printf("The shared variable now equals %ld\n",sharedvar);
  51.  
  52.     /* We can simply remove the task we added because our simpletask does not make */
  53.     /* any system calls which could cause it to be awakened or signalled later.    */
  54.     Forbid();
  55.     DeleteTask(task);
  56.     Permit();
  57.     cleanexit("",RETURN_OK);
  58. }
  59.  
  60. void simpletask()
  61. {
  62.     while(sharedvar < 0x8000000) sharedvar++;
  63.     /* Wait forever because main() is going to RemTask() us */
  64.     Wait(0L);
  65. }
  66.  
  67. void cleanexit(UBYTE *s, LONG e)
  68. {
  69.     if(*s) printf("%s\n",s);
  70.     exit(e);
  71. }
  72.