Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <setjmp.h>
- #include <unistd.h>
- #include <stdlib.h>
- sigjmp_buf jmp_env1;
- sigjmp_buf jmp_env2;
- void testjmp() {
- printf("first run\n");
- int y = 5;
- if (sigsetjmp(jmp_env2, 1)) {
- printf("jmp from main, y=%d\n", y);
- siglongjmp(jmp_env1, 1);
- } else {
- printf("didn't jmp from main, y=%d\n", y);
- siglongjmp(jmp_env1, 1);
- }
- }
- int main()
- {
- if (sigsetjmp(jmp_env1, 1))
- {
- printf("jump from testjmp\n");
- usleep(1000000);
- siglongjmp(jmp_env2, 1);
- } else {
- printf("didn't jmp from testjmp\n");
- testjmp();
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment