This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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: GCC 3.0 and 3.0.3 bug of string implemenation and the fix


On Tue, Jan 15, 2002 at 06:44:34PM -0500, Mike Lu wrote on gcc-bugs:
>      We have encountered a serious bug in multi-thread code when using
> string with GCC3.0 and GCC3.0.3 on sparc-solaris-2.8 dual CPU system.

Have you applied the following patch?  (I had thought it was supposed
to appear in 3.0.3, but apparently will be in 3.0.4, if any.)  IMHO this 
should be mentioned prominently in the release notes for the sparc32
target.

Nathan Myers
ncm at cantrip dot org

Index: config/cpu/sparc/sparc32/bits/atomicity.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/config/cpu/sparc/sparc32/bits/atomicity.h,v
retrieving revision 1.2.6.1
diff -c -r1.2.6.1 atomicity.h
*** atomicity.h	2001/02/28 00:04:10	1.2.6.1
--- atomicity.h	2001/12/27 05:21:35
***************
*** 32,42 ****
  
  typedef int _Atomic_word;
  
  static int
  __attribute__ ((__unused__))
  __exchange_and_add (volatile _Atomic_word* __mem, int __val)
  {
-   static unsigned char __lock;
    _Atomic_word __result, __tmp;
  
    __asm__ __volatile__("1:	ldstub	[%1], %0\n\t"
--- 32,52 ----
  
  typedef int _Atomic_word;
  
+ template <int __inst>
+ struct __Atomicity_lock
+ {
+   static unsigned char _S_atomicity_lock;
+ };
+ 
+ template <int __inst>
+ unsigned char __Atomicity_lock<__inst>::_S_atomicity_lock = 0;
+ 
+ template unsigned char __Atomicity_lock<0>::_S_atomicity_lock;
+ 
  static int
  __attribute__ ((__unused__))
  __exchange_and_add (volatile _Atomic_word* __mem, int __val)
  {
    _Atomic_word __result, __tmp;
  
    __asm__ __volatile__("1:	ldstub	[%1], %0\n\t"
***************
*** 44,56 ****
  		       "	bne	1b\n\t"
  		       "	 nop"
  		       : "=&r" (__tmp)
! 		       : "r" (&__lock)
  		       : "memory");
    __result = *__mem;
    *__mem += __val;
    __asm__ __volatile__("stb	%%g0, [%0]"
  		       : /* no outputs */
! 		       : "r" (&__lock)
  		       : "memory");
    return __result;
  }
--- 54,66 ----
  		       "	bne	1b\n\t"
  		       "	 nop"
  		       : "=&r" (__tmp)
! 		       : "r" (&__Atomicity_lock<0>::_S_atomicity_lock)
  		       : "memory");
    __result = *__mem;
    *__mem += __val;
    __asm__ __volatile__("stb	%%g0, [%0]"
  		       : /* no outputs */
! 		       : "r" (&__Atomicity_lock<0>::_S_atomicity_lock)
  		       : "memory");
    return __result;
  }
***************
*** 59,65 ****
  __attribute__ ((__unused__))
  __atomic_add (volatile _Atomic_word* __mem, int __val)
  {
-   static unsigned char __lock;
    _Atomic_word __tmp;
  
    __asm__ __volatile__("1:	ldstub	[%1], %0\n\t"
--- 69,74 ----
***************
*** 67,78 ****
  		       "	bne	1b\n\t"
  		       "	 nop"
  		       : "=&r" (__tmp)
! 		       : "r" (&__lock)
  		       : "memory");
    *__mem += __val;
    __asm__ __volatile__("stb	%%g0, [%0]"
  		       : /* no outputs */
! 		       : "r" (&__lock)
  		       : "memory");
  }
  
--- 76,87 ----
  		       "	bne	1b\n\t"
  		       "	 nop"
  		       : "=&r" (__tmp)
! 		       : "r" (&__Atomicity_lock<0>::_S_atomicity_lock)
  		       : "memory");
    *__mem += __val;
    __asm__ __volatile__("stb	%%g0, [%0]"
  		       : /* no outputs */
! 		       : "r" (&__Atomicity_lock<0>::_S_atomicity_lock)
  		       : "memory");
  }
  


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