Quantcast
Channel: Thread Lock Question
Viewing all articles
Browse latest Browse all 6

Thread Lock Question

$
0
0

 OmegaMan wrote:
Off the bat, you are locking a value type which gets copied on return of the getter. The setting and extracting are safe for _foo...but if your intention is does the lock remain if someone is using the Foo after doing a get, the answer is no.
LOCK is not a value type.  Or, do you mean the synchronized access to _Foo?

Reference assignments and built-in type assignments are guarenteed in the C# spec to be atomic; there's no need to synchronize them (you're simply adding overhead that isn't being used).

 

If you've got an invariant that you need to protect (i.e. you shouldn't set Foo during some other state), then you need to address that outside of the Foo property.


Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>