home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!bcstec!bcsaic!sinan
- From: sinan@bcsaic.boeing.com (Sinan Karasu)
- Newsgroups: comp.unix.questions
- Subject: swapcontext getcontext etc......
- Message-ID: <87535@bcsaic.boeing.com>
- Date: 19 Nov 92 04:38:31 GMT
- Distribution: comp.unix.questions,comp.unix.programmer,comp.unix.misc,comp.unix.sys5.r4,comp.unix.internals
- Organization: Boeing Computer Services AI Center, Seattle
- Lines: 74
-
- Here is a small program. What it is suppossed to do is
-
- metsun% rtt1
- Calling 1
- HELLO THERE 1
- Calling 2
- HELLO THERE 2
- Calling 3
- HELLO THERE 3
- ^Cmetsun%
-
- which it does except it gets hung up in the end.
- I can not get it to terminate ... I.e it never does
- a return to the OS ( which Sun Solaris 2 with SunPRO
- c compiler.... What am I doing wrong ??
- All and any remarks will be appreciated...
-
- (Note: I have written an assembly language version of this
- but I do not know how to handle the register windows.
- I save the registers in a "leaf procedure" but it hit me that
- the windows will be in an indeterminate position when I return
- from a procedure. If you think you can help me, give me an e-mail
- and I'll send you the code.... Thanx.....)
-
- Sinan Karasu
- sinan@mtesol.boeing.com
-
- -------------------------cut here---------------------------------------------
- #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);
- }
-