From: EricP on
jon wayne wrote:
> Hi
> I was trying to implement a flavor of barrier wait to synchronize
> pthreads( the machine's Xeon X5, running linux 2.6 and gcc 4.1.1).
> To ensure sequential conistency - i sprinkled my code with mfences -
> unfortunately i find the memory consistency being broken when i run
> this code. I was wondering if i've missed something?
> I'm using 3 booleans as the synchronization flags; have spread 'em
> across 3 cache lines to prevent false sharing. Am synchronizing 3
> threads (taking 3 as a small example)
> <snip>

What you are trying to do does not require fences on an x64
using normally allocated memory. When just doing reads or writes
to the shared variables as you are, as opposed to
read-modify-write, then you do not need atomic ops.

So if it doesn't work, you've buggered something up :-)
(e.g. what was X init'ed to before you started the worker threads?)

comp.programming.threads is a good place for threading questions.