gnu.gcc.help
[Top] [All Lists]

Re: Catching SIGFPE two times

Subject: Re: Catching SIGFPE two times
From: thomas.mertes@xxxxxx
Date: Sat, 12 Jul 2008 00:09:03 -0700 (PDT)
Newsgroups: gnu.gcc.help

On 11 Jul., 22:11, Andrew Haley
<a...@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> thomas.mer...@xxxxxx wrote:
>
> > Has someone an idea how a program can have more than
> > one SIGFPE catched with a setjmp/longjmp exception?
>
> Because you used longjmp() to leave the handler, the kernel thinks
> you're still in the handler!  You need to re-enable the handler with
> sigprocmask(2)
>
>   sigset_t sigs;
>   sigemptyset (&sigs);
>   sigaddset (&sigs, signum);
>   sigprocmask (SIG_UNBLOCK, &sigs, NULL);
Should sigprocmask() be called in the signal handler?
What about using siglongjmp() instead of longjmp()?
Can it avoid that the kernel thinks you're still in the handler?
What about using a signal mask of -1 with sigsetjmp?
In the example mentioned in the original post I replaced

  setjmp(catch_pos);

with

  sigsetjmp(catch_pos, -1);

and

  longjmp(catch_pos, 1);

with

  siglongjmp(catch_pos, 1);

and the program worked. The output of the tesprogram
now is:

tm@penguin$ ./a.out
before division A catch_pos=80498e0
in handle_fpe_signal catch_pos=80498e0
handler A
---------- A
before division B catch_pos=80498e0
in handle_fpe_signal catch_pos=80498e0
handler B
---------- B
tm@penguin$

Which indicates that it works.
Can it be that it works only by coincidence?

Greetings Thomas Mertes

Seed7 Homepage:  http://seed7.sourceforge.net
Seed7 - The extensible programming language: User defined statements
and operators, abstract data types, templates without special
syntax, OO with interfaces and multiple dispatch, statically typed,
interpreted or compiled, portable, runs under linux/unix/windows.

<Prev in Thread] Current Thread [Next in Thread>