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

  1. Newsgroups: comp.unix.programmer
  2. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!usenet.coe.montana.edu!news.u.washington.edu!carson.u.washington.edu!sinan
  3. From: sinan@carson.u.washington.edu (Sinan Karasu)
  4. Subject: swapcontext etc...
  5. Message-ID: <1992Nov19.222413.8027@u.washington.edu>
  6. Sender: news@u.washington.edu (USENET News System)
  7. Organization: University of Washington, Seattle
  8. Date: Thu, 19 Nov 1992 22:24:13 GMT
  9. Lines: 73
  10.  
  11. Hi,
  12. The following code runs as it should but then hangs.
  13. The output should be :
  14.  
  15. metsun% rtt1
  16.  Calling 1 
  17.  HELLO THERE 1 
  18.  Calling 2 
  19.  HELLO THERE 2 
  20.  Calling 3 
  21.  HELLO THERE 3 
  22. metsun% 
  23.  
  24. Without the Control-C ( I always have to abort it).
  25. What I want it to do is to return back to main and stop. 
  26. What am I doing wrong?
  27.  
  28. Environment: 
  29. Sparc2
  30. Solaris2
  31.  
  32.  
  33. --------------------------------------------------------------------------------
  34.  
  35.  
  36. #include <ucontext.h>
  37. ucontext_t test_cp,exec_cp;
  38. void rtt_exec(mode,func)
  39. int mode;
  40. void func();
  41. {
  42.    switch (mode) {
  43.     case 1: /* Remember the address of  */
  44.                 getcontext(&test_cp);
  45.                 makecontext(&test_cp,func,0);
  46.                 return;
  47.      case 2: /* Execute the TEST routine */
  48.         swapcontext(&exec_cp,&test_cp);
  49.         return;
  50.    }
  51.  }
  52.  
  53. void rtt_return()
  54.         swapcontext(&test_cp,&exec_cp);
  55.     return;  
  56. }
  57. void TEST()
  58.  
  59. {    printf(" HELLO THERE 1 \n");
  60.      rtt_return();
  61.      printf(" HELLO THERE 2 \n");
  62.      rtt_return();
  63.      printf(" HELLO THERE 3 \n");
  64.      return;
  65. }
  66. main()
  67.  
  68.  
  69.     rtt_exec(1,TEST);
  70.     printf(" Calling 1 \n");
  71.     rtt_exec(2);
  72.     printf(" Calling 2 \n");
  73.     rtt_exec(2);
  74.     printf(" Calling 3 \n");
  75.     rtt_exec(2);
  76. }
  77.  
  78.  
  79.  
  80.  
  81.  
  82.