KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have found several questions about this same topic but related to general variables (value and reference types) The accepted answer from this question says: Partition I, Section 12.6.6 of the CLI spec states: "A conforming CLI shall guarantee that read and write access to properly aligned memory locations no larger than the native word size is atomic when all the write accesses to a location are the same size." Reference variables (i.e. classes) are pointers, equal to the native word size, but I have a couple doubts: Are references guaranteed to be in properly aligned memory locations? I don't understand the last part. What does this mean? "...when all the write accesses to a location are the same size." In short, is obj2 guaranteed to be valid in every iteration of the loop in the following code? class MyClass { private OtherClass m_Object; void Thread1() { while(true) { OtherClass obj1 = new OtherClass(); m_Object = obj1; } } void Thread2() { while (true) { OtherClass obj2 = m_Object; // Is obj2 guaranteed to be valid? obj2.Check(); } } }
Tags (comma-separated)
Save Edits
Cancel