Re: Named shared memory without synchronization
- From: adebaene@xxxxxxxxxxxxxxxx
- Date: 24 Nov 2006 04:58:27 -0800
On 23 nov, 22:24, "Alex Blekhman" <x...@xxxxxxxxx> wrote:
"Dan Schwartz" wrote:
Is this really a stable solution?No. I'd suggest to use `volatile' specifier, so compilerwill be aware of possibility of asynchronous changes. In
your specific case optimizer didn't kick in for whatever
reason, but I wouldn't rely on that in the future.
I do not agree : The semantic of "volatile" as defined in the C
standard is so imprecise that it is almost useless. In any cases,
"volatile" is NOT a guarantee when delaling with multithreading
context. It MAY be usefull when writing low-level code that deals
directly with hardware (for example, directly reading a register that
is modified through some hardware piece). However, this is useless in a
Windows user application context, especially when multi-processors and
weak-cache semantic come into play.
As Igor has already explained, this doesn't hold true for VC8, which
gives precise and meaningfull semantic to volatile (ie : memory
barriers), but this is VC8-specific and is not portable.
To the OP : I would suggest accessing the shared variable through
Interlock* functions. (InterlockExchange for writing,
InterlockCompareExchange for reading). This avoid the cumbersom-ness of
adding a named mutex to protect the data, it is portable among
compilers and it is rather efficient at run-time. Of course, if you are
using VC8, making the variable volatile in both processes would be
equivalent.
Arnaud
MVP - VC
.
- Follow-Ups:
- Re: Named shared memory without synchronization
- From: Alex Blekhman
- Re: Named shared memory without synchronization
- References:
- Re: Named shared memory without synchronization
- From: Alex Blekhman
- Re: Named shared memory without synchronization
- Prev by Date: Re: Named shared memory without synchronization
- Next by Date: Re: What cause " stack overflow " ?
- Previous by thread: Re: Named shared memory without synchronization
- Next by thread: Re: Named shared memory without synchronization
- Index(es):
Relevant Pages
|
Loading