10-26-07 06:31 AM
I can't figure out why, but these functions don't work the way I
expect. What happens is that it gets the context fine in the call_cc
function and then it sets the context in the apply function just fine
- I know this because of the second "getcontext returned..." message.
But then instead of returning from call_cc just before the "main:
i=..." message, call_cc returnes at the point that apply was called -
and the "error! i=..." message is printed and the program ends. Why
is it doing something I don't expect?
Thanks,
Jerry
Compiler:
VisualAge C++ Professional / C for AIX Compiler, Version 6
Program:
#include <ucontext.h>
#include <stdio.h>
ucontext_t context = {0};
void call_cc(int i) {
printf("call_cc: i=%d\n",i);
int x = getcontext(&context);
printf("getcontext returned %d\n",x);
}
void apply(int i) {
printf("apply: i=%d\n",i);
int x = setcontext(&context);
printf("setcontext returned %d\n",x);
}
int main() {
int i=0;
call_cc(i);
printf("main: i=%d\n",i);
if(i==0) {
i++;
apply(i);
printf("error! i=%d\n",i);
}
printf("done! i=%d\n",i);
return 0;
}
Actual Output:
call_cc: i=0
getcontext returned 0
main: i=0
apply: i=1
getcontext returned 0
error! i=1
done! i=1
Expected Output:
call_cc: i=0
getcontext returned 0
main: i=0
apply: i=1
getcontext returned 0
main: i=1
done! i=1
[ Post a follow-up to this message ]
|