Hello PARI-dev,
I am investigating the issues of GP misbehaving (hanging, crashing,
etc.) after a SIGINT (Control-C interrupt). Examples can be found in
bugs #458 and #488.
The rather crude patch should improve a lot the situation. It works
by delaying handling of SIGINT that occurs during malloc/realloc/free
calls after the call is completed.
Please test thoroughly. If it still hang, please try to attach a
debugger and get a backtrace, this would help a lot.
When GP get a SIGINT it will 'try to recover' and then longjmp to the
main loop. The issue is that some part of the memory might be in an
inconsistent state. PARI/GP try hard to avoid that to happen.
The situation is:
- system stack: this is reset by longjmp itself.
- PARI stack: this is reset by GP
- PARI heap: this is recovered by try_to_recover().
- system heap: not recovered.
Since it is not possible to recover system heap, we should delay
handling of SIGINT after functions that operate on the system heap
have completed. The patch take care of the most frequent ones:
malloc/realloc/free. Other functions could be covered if the need
arise.
The patch works by adding two boolean variables, pari_do_sigint and
pari_did_sigint:
pari_do_sigint: whether SIGINT should be handled (1) or deferred(0)
pari_did_sigint: whether there is a pending SIGINT.
User installed handlers are not affected unless they manage these
variables themselves.
Cheers,
Bill.