gcc static constructor multi-threading flaw

Christopher Faylor cgf@redhat.com
Wed Mar 5 05:07:00 GMT 2003


On Fri, Feb 14, 2003 at 10:09:44AM -0500, Joe Buehler wrote:
>Would you accept patches to gcc / cygwin to add locking to
>function-private static object constuction?
>
>Gcc generates calls to atexit() when entering a function that has a
>private static object.  It does this to schedule a call to the
>destructor at program exit time.
>
>The atexit() function is not thread-safe, however.  I posted an
>explanation to the newlib list, but looking at the newlib code, it
>appears that newlib is not really set up for locking, so a fix is
>probably not going to be forthcoming from there.
>
>One possible fix is to have gcc call a wrapper function that performs
>locking and then calls atexit().  I suppose another way to do it
>without touching gcc is #define manipulation to replace atexit() with a
>Cygwin wrapper.

Since neither gcc nor newlib have responded to this problem, I've
added a wrapper in cygwin.  It will be in 1.3.21.

cgf



More information about the Cygwin-developers mailing list