N
n_o_s_p_a__m
Hi, just a quick question:
I have 2 objects running in their own threads (let's call them a & b).
They both hold a reference to a common object running in a third
thread (call it c) which has a public boolean field called bCool.
So:
// a & b
class One {
private Two _myTwo = null;
public One(Two t) {
_myTwo = t;
}
public void ChangebCool(bool newVal) {
_myTwo.bCool = newVal; // safe?
}
}
// c
class Two {
public volatile bool bCool = false;
}
Both a and b can thus read and update bCool.
Is there any risk of a and b colliding on these operations?
Are boolean's thread-safe?
Is volatile even needed?
Should a & b use Interlocked.Exchange() update bCool?
Or what.
Thanks.
I have 2 objects running in their own threads (let's call them a & b).
They both hold a reference to a common object running in a third
thread (call it c) which has a public boolean field called bCool.
So:
// a & b
class One {
private Two _myTwo = null;
public One(Two t) {
_myTwo = t;
}
public void ChangebCool(bool newVal) {
_myTwo.bCool = newVal; // safe?
}
}
// c
class Two {
public volatile bool bCool = false;
}
Both a and b can thus read and update bCool.
Is there any risk of a and b colliding on these operations?
Are boolean's thread-safe?
Is volatile even needed?
Should a & b use Interlocked.Exchange() update bCool?
Or what.
Thanks.