This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch, libfortran] Thread safety and simplification of error printing


On May 8 2011, Janne Blomqvist wrote:

the error printing functionality (in io/unix.c) st_printf and st_vprintf are not thread-safe as they use a static buffer. ...

While this patch makes error printing thread-safe, it's no longer async-signal-safe as the stderr lock might lead to a deadlock. So I'm retracting this patch and thinking some more about this problem.

It's theoretically insoluble, given the constraints you are working under. Sorry. It is possible to do reasonably well, but there will always be likely scenarios where all you can do is to say "Aargh! I give up."

Both I and the VMS people adopted the ratchet design.  You have N
levels of error recovery, each level allocates all of the resources
it needs before startup, and any exception during level K increases
the level to K+1 and calls the level K+1 error handler.  When you
have an exception at level N, you just die.

That imposes the constraint that all diagnostics have a fixed upper
bound on the resources they need (not just buffer space, but that's
the main one).  It's a real bummer when the system has some critical
resources that you can't reserve, so you have to treat an allocation
failure as an exception, but buffer space is not one such.

That also tackles the thread problem, not very satisfactorily.  If a
resource needs to be locked, you can try to get it for a bit, and
then raise a higher exception if you can't.  And, typically, one or
more of the highest levels are for closing down the process, and
simply suspend any subsequent threads that call them (i.e. just leave
them waiting for a lock they won't get).

Yes, it's not pretty. But I don't know how to do better.

Regards,
Nick Maclaren.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]