Help: Unwinding the C++ stack...throw, longjmp & threads
Joe Buck
jbuck@synopsys.COM
Tue Aug 31 23:20:00 GMT 1999
> >Making try, catch, and throw available in C would be a nice GNU
> >extension,
...
Josh writes:
> If this extension would allow exceptions to be thrown from
> Unix signal handlers, that would be a very cool feature
> for even non-threaded programs.
It wouldn't, since we don't support that in C++ either. The problem
is that signals can happen anywhere. Consider
char * buf = 0;
try {
buf = malloc(buf_size);
}
catch (SIGNAL) {
if (buf)
free(buf);
}
This code has a race and a leak, and there's no way to write it correctly,
because the signal could come after malloc has allocated memory but before
buf is assigned.
I suppose there could be a mechanism to queue signals and throw exceptions
at "safe" points.
More information about the Gcc
mailing list