context switching with setjmp
From: aditya (adityavasishth_at_gmail.com)
Date: 09/22/04
- Next message: ranjeet: "Re: Problem with DO-WHILE Loop"
- Previous message: Allin Cottrell: "Re: Newbie-question: scanf alternatives?"
- Next in thread: Jack Klein: "Re: context switching with setjmp"
- Reply: Jack Klein: "Re: context switching with setjmp"
- Reply: SM Ryan: "Re: context switching with setjmp"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 21 Sep 2004 20:50:39 -0700
hi all,
cananybody please tell me that why the control transfers to f() and
then g() and then f() and so on,when longjmp(jbuf[0],1) is called in
main.
Here is the complete code.
#include <stdio.h>
#include <setjmp.h>
#include <signal.h>
#define SECOND 1000000
char stack1[4096];
char stack2[4096];
jmp_buf jbuf[2];
f()
{
int i=0;
while(1){
printf("in f (%d)\n",i++);
usleep(SECOND);
}
}
g()
{
int i=0;
while(1){
printf("in g (%d)\n",i++);
usleep(SECOND);
}
}
setup()
{
sigsetjmp(jbuf[0],1);
jbuf[0][0].__jmpbuf[JB_SP] = (unsigned) stack1 + 4096;
jbuf[0][0].__jmpbuf[JB_PC] = (unsigned) f;
sigsetjmp(jbuf[1],1);
jbuf[1][0].__jmpbuf[JB_SP] = (unsigned) stack2 + 4096;
jbuf[1][0].__jmpbuf[JB_PC] = (unsigned) g;
}
static toggle = 0;
void dispatch(int sig)
{
puts("in dispatch");
if (sigsetjmp(jbuf[toggle],1) == 1)
return;
puts("DISPATCH");
toggle = 1 - toggle;
siglongjmp(jbuf[toggle],1);
}
main()
{
signal(SIGALRM, dispatch);
setup();
ualarm(5*SECOND, 5*SECOND);
longjmp(jbuf[0],1);
}
- Next message: ranjeet: "Re: Problem with DO-WHILE Loop"
- Previous message: Allin Cottrell: "Re: Newbie-question: scanf alternatives?"
- Next in thread: Jack Klein: "Re: context switching with setjmp"
- Reply: Jack Klein: "Re: context switching with setjmp"
- Reply: SM Ryan: "Re: context switching with setjmp"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|