Re: WaitForSingleObject() will not deadlock
- From: Frank Cusack <fcusack@xxxxxxxxxxx>
- Date: Thu, 05 Jul 2007 17:04:34 -0700
On Tue, 03 Jul 2007 13:53:09 -0400 Joseph M. Newcomer <newcomer@xxxxxxxxxxxx> wrote:
It seems that "memory visibility" has something to do with making
sure that results are in memory. I would have thought this would
have been more commonly referred to as the "cache coherency"
problem.
They are 2 different problems, but because x86 is TSO, they are
equivalent for that platform.
Because of the Interlocked operation used on the x86 and
x64, all results in caches and pipes are guaranteed to be in a
consistent state throughout the entire multiprocessor cache
structure. Therefore, once you have acquired any locking object,
you are guaranteed that all processors are seeing the same memory
contents, one way or another.
That is true for all processors, but this is because acquisition of a
lock is guaranteed to issue a membar, not because of cache coherency.
Strictly speaking, shared variables should be declared 'volatile' to
ensure the compiler has not kept a copy around, and this is
Strictly speaking, this is not correct. But the MS VC definition
of volatile is different than the ISO C definition. This has been
discussed to death on comp.programming.threads. Again and again.
completely orthogonal to the concept of locking; it appears that the
Microsoft C/C++ compiler is very conservative about code motions
across functions and therefore seems less subject to this kind of
error, although the formal requirements of the C/C++ language would
dictate that the use of 'volatile' is mandatory to ensure the
compiler has not done something bad.
Not correct. volatile (the ISO C definition) does no such thing.
A mutex is sufficient to guarantee visibility, and the compiler
is guaranteed not to reorder code around locking operations.
-frank
.
- Follow-Ups:
- Re: WaitForSingleObject() will not deadlock
- From: Joseph M . Newcomer
- Re: WaitForSingleObject() will not deadlock
- References:
- Re: WaitForSingleObject() will not deadlock
- From: Joseph M . Newcomer
- Re: WaitForSingleObject() will not deadlock
- From: Frank Cusack
- Re: WaitForSingleObject() will not deadlock
- From: Joseph M . Newcomer
- Re: WaitForSingleObject() will not deadlock
- From: Alexander Grigoriev
- Re: WaitForSingleObject() will not deadlock
- From: Frank Cusack
- Re: WaitForSingleObject() will not deadlock
- From: Alexander Grigoriev
- Re: WaitForSingleObject() will not deadlock
- From: Frank Cusack
- Re: WaitForSingleObject() will not deadlock
- From: Alexander Grigoriev
- Re: WaitForSingleObject() will not deadlock
- From: Joseph M . Newcomer
- Re: WaitForSingleObject() will not deadlock
- Prev by Date: Re: WaitForSingleObject() will not deadlock
- Next by Date: Re: WaitForSingleObject() will not deadlock
- Previous by thread: Re: WaitForSingleObject() will not deadlock
- Next by thread: Re: WaitForSingleObject() will not deadlock
- Index(es):
Relevant Pages
|
Loading