G
Guest
I'm having a tough time understanding the concept of locking "on an object".
If a monitor is used to protect a critial section, then what does any object
reference have to do with it? Does this allow different instances of the
same object to, in fact, run the same critical section and assume they're
accessing instance varaibles only?
What would be a scenario where some method in class A would lock on an
instance of class B?
If you're locking to protect global (static) data structures, then you lock
on typeof(this), right? Well... what does that mean? You've locked on an
instance of the Type class, so no other instance can run that critical
section?
I guess I just don't understand why you need the object reference. This
also leaves me a little confused on the SyncRoot property of may collections.
Is locking on 'this' not good enough? Do I actually have to lock on the
underlying data structure to assure thread safety.
Thanks,
Andrew
If a monitor is used to protect a critial section, then what does any object
reference have to do with it? Does this allow different instances of the
same object to, in fact, run the same critical section and assume they're
accessing instance varaibles only?
What would be a scenario where some method in class A would lock on an
instance of class B?
If you're locking to protect global (static) data structures, then you lock
on typeof(this), right? Well... what does that mean? You've locked on an
instance of the Type class, so no other instance can run that critical
section?
I guess I just don't understand why you need the object reference. This
also leaves me a little confused on the SyncRoot property of may collections.
Is locking on 'this' not good enough? Do I actually have to lock on the
underlying data structure to assure thread safety.
Thanks,
Andrew