Hi,
I'm having a problem with one of the Boost.Atomic tests on a PowerPC64
LE test platform. The test is running two threads which are looping code
like this:
Thread 1 Thread 2
[initially a == 0 && b == 0]
a.store(1, seq_cst); b.store(1, seq_cst);
a.load(relaxed); b.load(relaxed);
x = b.load(relaxed); y = a.load(relaxed);
On each iteration the test verifies that !(x == 0 && y == 0) and this
check fails. As far as I can tell the test is valid and it indeed passes
on x86. Boost.Atomic uses __atomic* intrinsics in both cases, so from
C++ perspective the implementation is the same.
I don't have the access to the tester that fails, so I can't tell the
exact GCC version that is used there, only that it is labeled as 6.0. I
did some experimenting on the version 4.9.2 that I have locally and
found out that for code like this:
__atomic_store_n(&n, 1, __ATOMIC_SEQ_CST);
gcc generates this assembly:
1c: 01 00 40 39 li r10,1
20: ac 04 00 7c sync
24: 00 00 49 91 stw r10,0(r9)
I would expect that for seq_cst there should be a second 'sync' right
after the store, but it is absent. If 6.0 generates the similar code
then this might explain the test failures I'm seeing.
So my questions are:
1. Is my test valid or is there a flaw that I'm missing?
2. Am I correct about the missing 'sync' instruction?
Thanks.
PS: If you're interested, here's the full code snippet I compiled:
int n = 0;
int main()
{
__atomic_store_n(&n, 1, __ATOMIC_SEQ_CST);
return n;
}
The command line was:
powerpc64le-linux-gnu-g++ -g -O0 -o seq_cst_ppc64el.o -c ./seq_cst.cpp
And here's the link to the original Boost.Atomic test:
https://github.com/boostorg/atomic/blob/develop/test/ordering.cpp