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

Thread Lock Question

$
0
0
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.

For the lock is only local that scope and once the item is extracted the lock is off. The lock is just a convenient way to say (this is a simplified example there is more too it)

Moniter.Enter(lockobj);

.... the code

Moniter.Exit(lockobj);

Once exit is hit it is turned off. See this article Threading in C# which is a good place to learn about the concepts.



Viewing all articles
Browse latest Browse all 6

Trending Articles



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