Re: Are static array pointers thread safe?
On Fri, 30 Nov 2007 08:30:17 -0800 (PST), flowstudioLA@gmail.com wrote:
Excellent reply Doug. You answered all my questions. Will definitely
be doing some research on memory barriers. It's interesting to note
that on just a cursory search on volatile memory barrier semantics,
there seems to be some debate as to its usefulness in regards to
memory barriers.
VC2005 does add memory barrier semantics to volatile, for those
architectures for which it matters, which makes the performance of volatile
even worse (far worse). Rather than sanctifying volatile for
multithreading, this is another reason to avoid it when you can, which is
*all of the time* if you use synchronization.
Also, from reading it seems to be hardware dependent,
but looks like my x86 processors fare better. There's much research I
need to do here.
Don't get too hung up on memory barriers. If you always use synchronization
such as mutexes (the Windows CRITICAL_SECTION is a type of mutex), you can
remain blissfully ignorant of memory barriers. Don't get too hung up on
volatile. If you always use synchronization, you can remain blissfully
ignorant of volatile. It's only when you don't use synchronization and thus
don't benefit from the memory visibility properties implied by it that you
need to get into this lower level stuff.
--
Doug Harrison
Visual C++ MVP