home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.programmer
- 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
- From: sinan@carson.u.washington.edu (Sinan Karasu)
- Subject: swapcontext etc...
- Message-ID: <1992Nov19.222413.8027@u.washington.edu>
- Sender: news@u.washington.edu (USENET News System)
- Organization: University of Washington, Seattle
- Date: Thu, 19 Nov 1992 22:24:13 GMT
- Lines: 73
-
- Hi,
- The following code runs as it should but then hangs.
- The output should be :
-
- metsun% rtt1
- Calling 1
- HELLO THERE 1
- Calling 2
- HELLO THERE 2
- Calling 3
- HELLO THERE 3
- metsun%
-
- Without the Control-C ( I always have to abort it).
- What I want it to do is to return back to main and stop.
- What am I doing wrong?
-
- Environment:
- Sparc2
- Solaris2
-
-
- --------------------------------------------------------------------------------
-
-
- #include <ucontext.h>
- ucontext_t test_cp,exec_cp;
- void rtt_exec(mode,func)
- int mode;
- void func();
- {
- switch (mode) {
- case 1: /* Remember the address of */
- getcontext(&test_cp);
- makecontext(&test_cp,func,0);
- return;
- case 2: /* Execute the TEST routine */
- swapcontext(&exec_cp,&test_cp);
- return;
- }
- }
-
- void rtt_return()
- {
- swapcontext(&test_cp,&exec_cp);
- return;
- }
- void TEST()
-
- { printf(" HELLO THERE 1 \n");
- rtt_return();
- printf(" HELLO THERE 2 \n");
- rtt_return();
- printf(" HELLO THERE 3 \n");
- return;
- }
- main()
-
- {
-
- rtt_exec(1,TEST);
- printf(" Calling 1 \n");
- rtt_exec(2);
- printf(" Calling 2 \n");
- rtt_exec(2);
- printf(" Calling 3 \n");
- rtt_exec(2);
- }
-
-
-
-
-
-