tTry to avoid races in underlying C library during threadexitsall. - plan9port - [fork] Plan 9 from user space
 (HTM) git clone git://src.adamsgaard.dk/plan9port
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 9689b580bdb168b87a20a5e466864337d591acfa
 (DIR) parent 5f4529e351e77e4ab61d258ca3dea69852a1e0ba
 (HTM) Author: rsc <devnull@localhost>
       Date:   Wed, 27 Jul 2005 20:25:34 +0000
       
       Try to avoid races in underlying C library
       during threadexitsall.
       
       Diffstat:
         M src/libthread/BSD.c                 |      14 ++++++++++++++
         M src/libthread/Linux.c               |      14 ++++++++++++++
       
       2 files changed, 28 insertions(+), 0 deletions(-)
       ---
 (DIR) diff --git a/src/libthread/BSD.c b/src/libthread/BSD.c
       t@@ -285,6 +285,20 @@ threadexitsall(char *msg)
                int i, npid, mypid;
                Proc *p;
        
       +        /* 
       +         * Only one guy, ever, gets to run this.
       +         * If two guys do it, inevitably they end up
       +         * tripping over each other in the underlying
       +         * C library exit() implementation, which is
       +         * trying to run the atexit handlers and apparently
       +         * not thread safe.  This has been observed on
       +         * both Linux and OpenBSD.  Sigh.
       +         */
       +        {
       +                static Lock onelock;
       +                lock(&onelock);
       +        }
       +
                if(msg == nil)
                        msg = "";
                mypid = getpid();
 (DIR) diff --git a/src/libthread/Linux.c b/src/libthread/Linux.c
       t@@ -311,6 +311,20 @@ threadexitsall(char *msg)
                int i, npid, mypid;
                Proc *p;
        
       +        /* 
       +         * Only one guy, ever, gets to run this.
       +         * If two guys do it, inevitably they end up
       +         * tripping over each other in the underlying
       +         * C library exit() implementation, which is
       +         * trying to run the atexit handlers and apparently
       +         * not thread safe.  This has been observed on
       +         * both Linux and OpenBSD.  Sigh.
       +         */
       +        {
       +                static Lock onelock;
       +                lock(&onelock);
       +        }
       +
                if(msg == nil)
                        msg = "";
                mypid = getpid();