Guest User

Untitled

a guest
May 23rd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <setjmp.h>
  3. #include <unistd.h>
  4. #include <stdlib.h>
  5.  
  6. sigjmp_buf jmp_env1;
  7. sigjmp_buf jmp_env2;
  8.  
  9. void testjmp() {
  10. printf("first run\n");
  11. int y = 5;
  12. if (sigsetjmp(jmp_env2, 1)) {
  13. printf("jmp from main, y=%d\n", y);
  14. siglongjmp(jmp_env1, 1);
  15. } else {
  16. printf("didn't jmp from main, y=%d\n", y);
  17. siglongjmp(jmp_env1, 1);
  18. }
  19. }
  20.  
  21. int main()
  22. {
  23. if (sigsetjmp(jmp_env1, 1))
  24. {
  25. printf("jump from testjmp\n");
  26. usleep(1000000);
  27. siglongjmp(jmp_env2, 1);
  28. } else {
  29. printf("didn't jmp from testjmp\n");
  30. testjmp();
  31. }
  32.  
  33. return 0;
  34. }
Add Comment
Please, Sign In to add comment