[PATCHv2] powerpc: Spinlock optimization and cleanup

Rich Felker dalias@libc.org
Thu Oct 1 19:27:00 GMT 2015


On Thu, Oct 01, 2015 at 09:17:06PM +0200, Torvald Riegel wrote:
> > (the issue is that for correct pthread_spin_trylock behavior
> > the lock should be seqcst instead of acquire and the unlock
> > should be release instead of barrier+store otherwise trylock
> > can spuriously report locked state).
> 
> Right now, unlock is a full barrier (ie, seqcst) plus store.  That is
> stronger than a release store.  Also note that a failing POSIX
> synchronization function is not supposed to synchronize memory.  So, a
> failing trylock doesn't help a program unless it synchronizes through
> some other way, in which case this other way will "provide" the
> barriers.

As always, the issue is not whether it synchronizes memory on failure,
but whether it can accurately determine whether to fail or not without
synchronizing memory. The latter is an implementation detail of
course, but in practice you can't make this determination without
synchronizing memory.

Rich



More information about the Libc-alpha mailing list