Created
May 18, 2018 13:10
-
-
Save thekoc/f77a29da760f859bc4bc85f20f24de1b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment