This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

What works as a data memory barrier?

We have a section of code that increments a variable shared among several threads. The code section is protected by a ldxr/stxr/dmb spin lock, and there is another dmb after the shared variable is updated. This code sequence is the body of a function that returns the shared variable's value before the update. The expectation is that no two calls to the function will return the same value. 

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
.text
## lap for synchtest
## 8 threads call this 100 times each, concurrently.
## x1 -> quadword used as a spin lock
## x2 -> quadword supposed to source a series of distinct
## values.
##
.align 4
.global synchtest
.type synchtest, %function
synchtest:
movz x20,6
mov x12,sp
str x30,[sp,8]
sub sp,sp,144
str x12,[sp,0]
str x20,[sp,16]
## Enter ctitical section control
## (loop until [x0] goes 0->1)
L15182:
movz x27,1
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

We start 8 threads running concurrently, calling the function 100 times each and record the results separately for each thread. Then we compare the sequences of values each thread received and check for duplications, where two threads got the same value. [EDIT: added: ] Our expectation is that there will be no duplicates. We find this is not the case.

Btw, we're on ARMv8 with CentOS 7.x (x = latest).

0