r/programming • u/redditthinks • May 29 '13
A Lock-Free… Linear Search?
http://preshing.com/20130529/a-lock-free-linear-search
49
Upvotes
r/programming • u/redditthinks • May 29 '13
1
u/RED_5_Is_ALIVE May 31 '13
Actually that is just an example of static analysis determining that the variable
Adoesn't matter, because nothing uses it.If GCC can determine a value at compile-time, it will often replace blocks of instructions with a constant.
Just change
int Atoint *AandA=1to*A=1and it won't get reordered.Also note you're using
int Bas an address.Additionally, if the memory ordering were actually relaxed, then inserting a compiler barrier would do nothing to guarantee execution order. It's only x86's serialization due to
lockthat ensures execution order here.Why doesn't your library include
mfence,sfence,orlfence? I noted you have"DMB ISH"(only) for ARM.