2

Will a Dictionary class marked as volatile, apply this behaviour to all the members inside the dictionary? Or better. An acces to a dictionary item through the dictionary pointer, does it have the same volatile behaviour? (meaning not caching in uProc registers).

volatile Dictionary<int,string> MyDictionary;
MyDictionary["somekey"] - is this volatile ?
svick
  • 236,525
  • 50
  • 385
  • 514
Mihai
  • 518
  • 4
  • 12

1 Answers1

4

This cannot possibly be the case. The CLR must know whether a given load or store is supposed to be volatile at the point in code where that access takes place. The code inside the dictionary has no idea whether the dictionary is being referenced from a volatile location or not. In fact, what about this:

volatile Dictionary d1 = new ...;
Dictionary d2 = d1;

There is only one dictionary here. Is the dictionary now internally volatile or not? Impossible to say because the notion of "propagated" volatility is inconsistent and makes no sense.

usr
  • 168,620
  • 35
  • 240
  • 369