Skip to content

Instantly share code, notes, and snippets.

@thekoc
Created May 18, 2018 13:10
Show Gist options
  • Save thekoc/f77a29da760f859bc4bc85f20f24de1b to your computer and use it in GitHub Desktop.
Save thekoc/f77a29da760f859bc4bc85f20f24de1b to your computer and use it in GitHub Desktop.
#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