home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / unix / question / 13630 < prev    next >
Encoding:
Text File  |  1992-11-19  |  2.0 KB  |  85 lines

  1. Path: sparky!uunet!bcstec!bcsaic!sinan
  2. From: sinan@bcsaic.boeing.com (Sinan Karasu)
  3. Newsgroups: comp.unix.questions
  4. Subject: swapcontext getcontext etc......
  5. Message-ID: <87535@bcsaic.boeing.com>
  6. Date: 19 Nov 92 04:38:31 GMT
  7. Distribution: comp.unix.questions,comp.unix.programmer,comp.unix.misc,comp.unix.sys5.r4,comp.unix.internals
  8. Organization: Boeing Computer Services AI Center, Seattle
  9. Lines: 74
  10.  
  11. Here is a small program. What it is suppossed to do is
  12.  
  13. metsun% rtt1
  14.  Calling 1 
  15.  HELLO THERE 1 
  16.  Calling 2 
  17.  HELLO THERE 2 
  18.  Calling 3 
  19.  HELLO THERE 3 
  20. ^Cmetsun% 
  21.  
  22. which it does except it gets hung up in the end. 
  23. I can not get it to terminate ... I.e it never does
  24. a return to the OS ( which Sun Solaris 2 with SunPRO
  25. c compiler.... What am I doing wrong ??
  26. All and any remarks will be appreciated...
  27.  
  28. (Note: I have written an assembly language version of this 
  29.        but I do not know how to handle the register windows.
  30.  I save the registers in a "leaf procedure" but it hit me that
  31.  the windows will be in an indeterminate position when I return
  32.  from a procedure. If you think you can help me, give me an e-mail
  33.  and I'll send you the code.... Thanx.....)
  34.  
  35. Sinan Karasu
  36. sinan@mtesol.boeing.com
  37.  
  38. -------------------------cut here---------------------------------------------
  39. #include <ucontext.h>
  40. ucontext_t test_cp,exec_cp;
  41. void rtt_exec(mode,func)
  42. int mode;
  43. void func();
  44. {
  45.    switch (mode) {
  46.     case 1: /* Remember the address of  */
  47.                 getcontext(&test_cp);
  48.                 makecontext(&test_cp,func,0);
  49.                 return;
  50.  
  51.      case 2: /* Execute the TEST routine */
  52.         swapcontext(&exec_cp,&test_cp);
  53.         return;
  54.    }
  55.  }
  56.  
  57.  
  58. void rtt_return()
  59.         swapcontext(&test_cp,&exec_cp);
  60.     return;  
  61. }
  62.  
  63. void TEST()
  64.  
  65. {    printf(" HELLO THERE 1 \n");
  66.      rtt_return();
  67.      printf(" HELLO THERE 2 \n");
  68.      rtt_return();
  69.      printf(" HELLO THERE 3 \n");
  70.      return;
  71. }
  72.  
  73. main()
  74.  
  75.     rtt_exec(1,TEST);
  76.     printf(" Calling 1 \n");
  77.     rtt_exec(2);
  78.     printf(" Calling 2 \n");
  79.     rtt_exec(2);
  80.     printf(" Calling 3 \n");
  81.     rtt_exec(2);
  82. }
  83.