469,571 Members | 1,533 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,571 developers. It's quick & easy.

lock statement

Does anyone know if there is any kind of known / published overhead with
using the lock statement (to lock an object to the current thread)? I am
preparing to use it in several object property gets, but I don't want to use
it if it will take a hit on performance.

Thanks,
Jon
Nov 15 '05 #1
1 8619

lock() should be employing a low-level critical section which is only a few
machine instructions and should have minimal overhead -- less than a Monitor
or Mutex object. In any case though, if you need lock() et. al . to ensure
the proper functioning of your class, then you need it -- if you don't then
you don't -- it doesn't really seem to be an option if you're telling user
it can be used in a threaded environment. With that said, I'd be surprsised
if any overhead is even measureable in a non-contrived use of your class.
(You could always put the locks in a #def and try w/ and w/o them...)
"Jon Davis" <jo*@REMOVE.ME.PLEASE.jondavis.net> wrote in message
news:uG**************@TK2MSFTNGP09.phx.gbl...
Does anyone know if there is any kind of known / published overhead with
using the lock statement (to lock an object to the current thread)? I am
preparing to use it in several object property gets, but I don't want to use it if it will take a hit on performance.

Thanks,
Jon

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Rich Sienkiewicz | last post: by
5 posts views Thread by harborboy76 | last post: by
7 posts views Thread by Sunny | last post: by
reply views Thread by Nashat Wanly | last post: by
5 posts views Thread by jeff.ranney | last post: by
94 posts views Thread by Samuel R. Neff | last post: by
reply views Thread by senthiltkp | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.