Hacker News new | past | comments | ask | show | jobs | submit login

It's odd to have a whole section on coherency and never mention the built-in `volatile` keyword who's entire purpose is to indicate that a variable requires fresh reads..



> In this case, the correct solution is to mark field _A as volatile. If that’s done, the compiler shouldn’t reorder the reads of _A and _B, because the load of _A has load-acquire semantics. However, I should point out that the .NET Framework, through version 4, doesn’t handle this case correctly and, in fact, marking the _A field as volatile will not prevent the read reordering. This issue has been fixed in the .NET Framework version 4.5.

From the article linked where they mention volatile and the C# memory model. Seems like volatile may not actually have worked as intended for this case!


I'm not saying volatile is a good solution, but to not cover it in this article is an odd omission - especially since he shows an explicit memory barrier.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: