Hello,
I am considering a piece of code that will manage access to a collection object from multiple threads - add, update, remove, clear.
OK ... so I have put a sync lock within each method, but what is not clear from the MS documentation is exactly how the sync lock is behaving.
Is it locking the piece of code it wraps? Or is it locking the object? And if it is locking the object a private static object should lock out any code locked on the object within all instances of the object? i.e. if an add operation is underway, an update, delete or clear will wait for the lock to be released.
Finally, if I have multiple threads contending for the sync lock, how is the release managed? First come, first serve? random (from my p.o.v)? Is there a chance that two separate threads could blunder into 'locked' code simulataneously?
Thanks
I am considering a piece of code that will manage access to a collection object from multiple threads - add, update, remove, clear.
OK ... so I have put a sync lock within each method, but what is not clear from the MS documentation is exactly how the sync lock is behaving.
Is it locking the piece of code it wraps? Or is it locking the object? And if it is locking the object a private static object should lock out any code locked on the object within all instances of the object? i.e. if an add operation is underway, an update, delete or clear will wait for the lock to be released.
Finally, if I have multiple threads contending for the sync lock, how is the release managed? First come, first serve? random (from my p.o.v)? Is there a chance that two separate threads could blunder into 'locked' code simulataneously?
Thanks