I have a question about legal instruction re-ordering in C#/.NET.
Let's start with this example. We have this method defined in some class, where _a, _b, and _c are fields.
int _a;
int _b;
int _c;
void Foo()
{
_a = 1; // Write 1
_b = 1; // Write 2
_c = 1; // Write 3
}
And our calling environment would look something like this.
//memory operations
ClassInstance.Foo();
//memory operations
I'm wondering what kind of legal instruction re-orderings are possible when this method call gets inlined vs a function call. More specifically, I'm wondering if/when is it legal to re-order memory operations within Foo(), with memory operations outside of it (from our previous example, the //memory operations).
Also, does a function call(no inline), in a sense, "generate memory barriers". As in, memory operations that happen before or after the function call cannot be re-ordered with memory operations within the function call.
If so, would it still have this "memory barrier" behavior when it gets inlined by the compiler?