[PATCH 1/2] Fixed pthread_spin_lock on sparc32/64 (bug 16882)

Guo Yixuan culu.gyx@gmail.com
Fri May 23 15:07:00 GMT 2014


From: GUO Yixuan <culu.gyx@gmail.com>

The bug occurs under this situation.
  1. thread1 gets the lock, set the byte to FF
  2. when thread2 is trying to lock, it enters the loop,
     checking whether the byte is 00
  3. thread1 unlocks, set to 00
  4. thread2 finally gets the lock, without setting to FF
  5. thread3 gets the lock, before thread2 unlocks it
---
 nptl/sysdeps/sparc/sparc32/pthread_spin_lock.S | 4 ++--
 nptl/sysdeps/sparc/sparc64/pthread_spin_lock.S | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/nptl/sysdeps/sparc/sparc32/pthread_spin_lock.S b/nptl/sysdeps/sparc/sparc32/pthread_spin_lock.S
index ea863d7..3accc69 100644
--- a/nptl/sysdeps/sparc/sparc32/pthread_spin_lock.S
+++ b/nptl/sysdeps/sparc/sparc32/pthread_spin_lock.S
@@ -19,11 +19,11 @@
 
 	.text
 ENTRY(pthread_spin_lock)
-	ldstub		[%o0], %g1
+1:	ldstub		[%o0], %g1
 	orcc		%g1, 0x0, %g0
 	bne,a		2f
 	 ldub		[%o0], %g1
-1:	retl
+	retl
 	 mov		0, %o0
 2:	orcc		%g1, 0x0, %g0
 	bne,a		2b
diff --git a/nptl/sysdeps/sparc/sparc64/pthread_spin_lock.S b/nptl/sysdeps/sparc/sparc64/pthread_spin_lock.S
index 0f849b2..aec6654 100644
--- a/nptl/sysdeps/sparc/sparc64/pthread_spin_lock.S
+++ b/nptl/sysdeps/sparc/sparc64/pthread_spin_lock.S
@@ -19,10 +19,10 @@
 
 	.text
 ENTRY(pthread_spin_lock)
-	ldstub		[%o0], %g1
+1:	ldstub		[%o0], %g1
 	brnz,pn		%g1, 2f
 	 membar		#StoreLoad | #StoreStore
-1:	retl
+	retl
 	 mov		0, %o0
 2:	ldub		[%o0], %g1
 	brnz,pt		%g1, 2b
-- 
2.0.0.rc2



More information about the Libc-alpha mailing list