home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / dev / rkrm.lha / RKRM / Exec_Library / Tasks / simpletask.c < prev    next >
C/C++ Source or Header  |  1992-09-03  |  3KB  |  97 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.  
  10. Copyright (c) 1992 Commodore-Amiga, Inc.
  11.  
  12. This example is provided in electronic form by Commodore-Amiga, Inc. for
  13. use with the "Amiga ROM Kernel Reference Manual: Libraries", 3rd Edition,
  14. published by Addison-Wesley (ISBN 0-201-56774-1).
  15.  
  16. The "Amiga ROM Kernel Reference Manual: Libraries" contains additional
  17. information on the correct usage of the techniques and operating system
  18. functions presented in these examples.  The source and executable code
  19. of these examples may only be distributed in free electronic form, via
  20. bulletin board or as part of a fully non-commercial and freely
  21. redistributable diskette.  Both the source and executable code (including
  22. comments) must be included, without modification, in any copy.  This
  23. example may not be published in printed form or distributed with any
  24. commercial product.  However, the programming techniques and support
  25. routines set forth in these examples may be used in the development
  26. of original executable software products for Commodore Amiga computers.
  27.  
  28. All other rights reserved.
  29.  
  30. This example is provided "as-is" and is subject to change; no
  31. warranties are made.  All use is at your own risk. No liability or
  32. responsibility is assumed.
  33. */
  34.  
  35. #include <exec/types.h>
  36. #include <exec/memory.h>
  37. #include <exec/tasks.h>
  38. #include <libraries/dos.h>
  39.  
  40. #include <clib/exec_protos.h>
  41. #include <clib/alib_protos.h>
  42.  
  43. #include <stdlib.h>
  44. #include <stdio.h>
  45.  
  46. #ifdef LATTICE
  47. int CXBRK(void) { return(0); }   /* Disable Lattice CTRL/C handling */
  48. int chkabort(void) {return(0);}
  49. #endif
  50.  
  51. #define STACK_SIZE 1000L
  52.  
  53. /* Task name, pointers for allocated task struct and stack */
  54. struct Task *task = NULL;
  55. char *simpletaskname = "SimpleTask";
  56.  
  57. ULONG sharedvar;
  58.  
  59. /* our function prototypes */
  60. void simpletask(void);
  61. void cleanexit(UBYTE *,LONG);
  62.  
  63. void main(int argc,char **argv)
  64. {
  65.     sharedvar = 0L;
  66.  
  67.     task = CreateTask(simpletaskname,0,simpletask,STACK_SIZE);
  68.     if(!task)  cleanexit("Can't create task",RETURN_FAIL);
  69.  
  70.     printf("This program initialized a variable to zero, then started a\n");
  71.     printf("separate task which is incrementing that variable right now,\n");
  72.     printf("while this program waits for you to press RETURN.\n");
  73.     printf("Press RETURN now: ");
  74.     getchar();
  75.  
  76.     printf("The shared variable now equals %ld\n",sharedvar);
  77.  
  78.     /* We can simply remove the task we added because our simpletask does not make */
  79.     /* any system calls which could cause it to be awakened or signalled later.    */
  80.     Forbid();
  81.     DeleteTask(task);
  82.     Permit();
  83.     cleanexit("",RETURN_OK);
  84. }
  85.  
  86. void simpletask()
  87. {
  88.     while(sharedvar < 0x8000000) sharedvar++;
  89.     /* Wait forever because main() is going to RemTask() us */
  90.     Wait(0L);
  91. }
  92.  
  93. void cleanexit(UBYTE *s, LONG e)
  94. {
  95.     if(*s) printf("%s\n",s);
  96.     exit(e);
  97. }