Peter said:
[...]
Declaring a variable volatile does not only effect access
to that variable.
The word is "affect".
Yeah.
It also effect access to all other places in memory, because
the .NET memory model limits what can be moved before and after
the access of the volatile variable.
Perhaps you are getting hung up on my particular use of the word
"affect". The point is that making the reference to the Hashtable
instance volatile doesn't provide any useful guarantees about using the
Hashtable object itself.
It provides some guarantees about access to the the Hashtable.
The original poster did not provide enough to say whether it was
useful guarantees or not.
The "volatile" keyword necessarily has certain effects that may extend
past the variable itself, but the only guarantees provided are with
respect to how things are ordered with respect to that specific variable.
Yes.
But the affect on the volatile variable itself is also just
about ordering of read and writes.
Same type of impact.
If you declare one variable referencing the Hashtable as "volatile", but
then always use the Hashtable from some other variable, nothing happens
to the uses of the Hashtable. Even if you reference the Hashtable
through the "volatile" variable, there are no useful guarantees about
the data in the Hashtable itself.
Since your original post did not mention anything about useful, then
we seem to agree now that your original post was indeed flat wrong.
And the not useful part is still purely speculation.
If you want to go on nitpicking about things that are completely
irrelevant and orthogonal to the original question, please be my guest.
1) It makes sense to me to correct wrong statements even it is not
relevant for the original poster, because other people read
the thread and there are no reason why they should end up having the
same misunderstandings about what volatiles does and does not.
2) It could be very relevant for the original poster. I don't know.
You don't know. Because we do not have the context. It could be
critical for the thread safety of his code. Or it could be
irrelevant.
I'm done trying to explain to you why your claim that my post was
incorrect is itself incorrect.
I think we have proven that is was flat wrong.
Arne