¿Los objetos en un diccionario volátil heredan el comportamiento volátil?

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 ?

preguntado el 28 de mayo de 14 a las 12:05

No, volatile applies to variable itself (so dictionary items or object properties won't heredar volatile modifier). -

1 Respuestas

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.

contestado el 28 de mayo de 14 a las 12:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.