Re: mutex question
- From: "Slava M. Usov" <stripit.slough@xxxxxxx>
- Date: Tue, 9 May 2006 15:48:33 +0200
"Tom Widmer [VC++ MVP]" <tom_usenet@xxxxxxxxxxx> wrote in message
news:uXcZKH2cGHA.5116@xxxxxxxxxxxxxxxxxxxxxxx
Slava M. Usov wrote:
[...]
Anyway, trying to redefine 'volatile', as you did, strikes me as a rather
strange way of discouraging.
Well, I don't think I did attempt to define volatile:
This is why the 'volatile' keyword exists -- to tell the compiler
that a variable can change unexpectedly, such as when it is shared
between threads. Today's compilers are smart, but they can't read
your mind (yet). :)
This was said by another person, and this is one of the standard definitions
almost verbatim, plus some commentary.
That is *not* what volatile is for - multithreading is not part of its
utility, rather hardware interaction is.
That doesn't look like a definition to me. There are two parts to my
statement.
1. volatile is not useful for multithreading.
That was overstating the case slightly (to combat the hoardes of
programmers who use it in a non-portable or incorrect manner for
multithreading), but it is useless in that better alternatives exist (at
least in the latest APIs).
2. volatile is useful for hardware interaction.
Do you disagree with this?
These two statement are slightly more balanced, not still not entirely
satisfactory. The original flat statement "X is not, Y is" was much less
satisfactory. This original statement was a redefinition not semantically
identical with the standard definitions.
[...]
Your statements:
On certain platforms, volatile is perfectly sufficient [for variables
shared between threads]. Incidentally, one of these platforms is a de
facto standard for win32.
Volatile is sufficient for any reads and writes. This is its entire and
only purpose.
My code demonstated the value of a shared volatile 64-bit variable
becoming corrupt (on Win32, single CPU) when being read and written.
Reads and writes did happen; your "corrupt" involves an ad hoc assumption --
the atomicity of reads and writes.
I am condemning its usage though, because it is neither necessary (ever
for multithreading on Windows) nor sufficient (except in a few special
cases).
C++, Windows, etc are neither necessary nor sufficient in the grand scheme
of things.
Can your present some VC8 compatible code using volatile for shared access
of a variable between threads where _ReadBarrier, _WriteBarrier and
Interlocked* wouldn't be more portable to other Windows platforms (and at
least as performant, if not more so)?
You're trying to reduce the use of 'volatile' to a nonsensical situation and
then say that 'volatile' is useless. The essence of my argument is that this
very reduction is incorrect.
S
.
- Follow-Ups:
- Re: mutex question
- From: Tom Widmer [VC++ MVP]
- Re: mutex question
- References:
- Re: mutex question
- From: David Jones
- Re: mutex question
- From: Tom Widmer [VC++ MVP]
- Re: mutex question
- From: Slava M. Usov
- Re: mutex question
- From: Tom Widmer [VC++ MVP]
- Re: mutex question
- From: Slava M. Usov
- Re: mutex question
- From: Tom Widmer [VC++ MVP]
- Re: mutex question
- From: Slava M. Usov
- Re: mutex question
- From: Tom Widmer [VC++ MVP]
- Re: mutex question
- From: Slava M. Usov
- Re: mutex question
- From: Tom Widmer [VC++ MVP]
- Re: mutex question
- Prev by Date: Re: Any way to get RTL_USER_PROCESS_PARAMETERS at NtCreateSection entry
- Next by Date: Re: Kernel debugging Howto
- Previous by thread: Re: mutex question
- Next by thread: Re: mutex question
- Index(es):
Relevant Pages
|
Loading