C
Cool Guy
(In thread A.)
{
Bar bar = new Bar();
lock (fooLock) {
foo = new Foo(bar); // is value of *bar* current here?
}
}
(In thread B.)
{
lock (fooLock) {
foo.DoSomethingWithBar(); // is *bar* value correct when used here?
}
}
Basically, an object which is accessed in multiple threads is being given a
reference to a local variable.
Will the lock in the above guarantee that the local variable's value, upon
reading, is current -- and that foo's bar reference is correct?
I assume so but I've never really thought about local variables in this
situation before.
{
Bar bar = new Bar();
lock (fooLock) {
foo = new Foo(bar); // is value of *bar* current here?
}
}
(In thread B.)
{
lock (fooLock) {
foo.DoSomethingWithBar(); // is *bar* value correct when used here?
}
}
Basically, an object which is accessed in multiple threads is being given a
reference to a local variable.
Will the lock in the above guarantee that the local variable's value, upon
reading, is current -- and that foo's bar reference is correct?
I assume so but I've never really thought about local variables in this
situation before.