Tag: compiler optimization

volatile是否会阻止引入读取或写入?

在C#中, volatile关键字分别确保读取和写入具有获取和释放语义。 但是,是否有关于引入读取或写入的内容? 例如: volatile Thing something; volatile int aNumber; void Method() { // Are these lines… var local = something; if (local != null) local.DoThings(); // …guaranteed not to be transformed into these by compiler, jitter or processor? if (something != null) something.DoThings(); // <– Second read! // Are these lines… if (aNumber == […]