longjmp

Longjmp out of signal handler?

烂漫一生 提交于 2019-11-27 14:02:20
From the question: Is it good programming practice to use setjmp and longjmp in C? Two of the comments left said: "You can't throw an exception in a signal handler, but you can do a longjmp safely -- as long as you know what you are doing. – Dietrich Epp Aug 31 at 19:57 @Dietrich: +1 to your comment. This is a little-known and completely-under-appreciated fact. There are a number of problems that cannot be solved (nasty race conditions) without using longjmp out of signal handlers. Asynchronous interruption of blocking syscalls is the classic example." I was under the impression that signal

OCaml internals: Exceptions

穿精又带淫゛_ 提交于 2019-11-27 11:49:18
问题 I'm curious to know how exceptions are dealt with in OCaml runtime to make them so lightweight. Do they use setjmp/longjmp or do they return a special value in each function, and propagate it? It seems to me that longjmp would put a little strain on the system, but only when an exception is raised, while checking for each function return value would need to check for every and each value after calling a function, which seems to me would put a lot of checks and jumps, and it seems it would

C++: Safe to use longjmp and setjmp?

淺唱寂寞╮ 提交于 2019-11-26 22:12:43
Is it safe to use longjmp and setjmp in C++ on linux/gcc with regards to the following? Exception handling (I'm not implementing exception handling using longjmp/setjmp. I want to know what side effects longjmp/setjmp will have on standard exception handling) *this pointer Signals Smart pointers (boost's shared and intrusive pointers) Anything else you can think of. setjmp() / longjmp() completely subvert stack unwinding and therefore exception handling as well as RAII (destructors in general). From 18.7/4 "Other runtime support" in the standard: If any automatic objects would be destroyed by

longjmp() from signal handler

无人久伴 提交于 2019-11-26 21:24:29
问题 I'm using the following code to try to read an input from user and timeout and exit if more than 5 seconds pass. This is accomplished through a combination of setjmp/longjmp and the SIGALRM signal. Here's the code: #include <stdio.h> #include <setjmp.h> #include <unistd.h> #include <string.h> #include <sys/signal.h> jmp_buf buffer; // this will cause t_gets() to return -2 void timeout() { longjmp(buffer, 1); } int t_gets(char* s, int t) { char* ret; signal(SIGALRM, timeout); if (setjmp(buffer

Longjmp out of signal handler?

爱⌒轻易说出口 提交于 2019-11-26 18:21:57
问题 From the question: Is it good programming practice to use setjmp and longjmp in C? Two of the comments left said: "You can't throw an exception in a signal handler, but you can do a longjmp safely -- as long as you know what you are doing. – Dietrich Epp Aug 31 at 19:57 @Dietrich: +1 to your comment. This is a little-known and completely-under-appreciated fact. There are a number of problems that cannot be solved (nasty race conditions) without using longjmp out of signal handlers.

C++: Safe to use longjmp and setjmp?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 08:16:54
问题 Is it safe to use longjmp and setjmp in C++ on linux/gcc with regards to the following? Exception handling (I\'m not implementing exception handling using longjmp/setjmp. I want to know what side effects longjmp/setjmp will have on standard exception handling) *this pointer Signals Smart pointers (boost\'s shared and intrusive pointers) Anything else you can think of. 回答1: setjmp()/longjmp() completely subvert stack unwinding and therefore exception handling as well as RAII (destructors in