[Gc] Allowing SIGINT during garbage collection may result in
blinke at cebitec.uni-bielefeld.de
Tue Apr 20 02:05:10 PDT 2010
On Tuesday 20 April 2010, Juan Jose Garcia-Ripoll wrote:
> 2010/4/20 Ivan Maidanski <ivmai at mail.ru>
> > Tue, 20 Apr 2010 09:57:04 +0200 Juan Jose Garcia-Ripoll <
> > juanjose.garciaripoll at googlemail.com>:
> > > It is not safe to call _almost_ _any_ function from a signal handler,
> > > not even malloc()
> > https://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_04.htm
> > > Signal handlers are useless in that respect, except for sending
> > > messages
> > to
> > > threads that actually do the job.
> > So, mono is broken in this respect.
> Quite probably so. I maintain a Common Lisp implementation (ECL) and it got
> us five years to realize this.
> Our current design uses a background thread that intercepts all signals. It
> then stores messages in queues of the appropriate Lisp threads and these
> queues are interrogated once we leave the signal unsafe regions.
> I agree this sucks, but it is all POSIX allows us. And we were bitten not
> too long ago because of the reentrancy problem, not only in GC, but also in
> file operations, etc, etc.
You are right, this problem does not only occur during garbage collection, but
affects every call to the garbage collector and other functions. I'll send a
bug report about this problem to the mono developers and try to create a
patch for handling signals in the correct way (using a semaphore and
sem_post(), which is the only async-safe way according to POSIX).
More information about the Gc