HighTechTalks DotNet Forums  

multiple locks

Dotnet Academic General Discussions microsoft.public.dotnet.academic


Discuss multiple locks in the Dotnet Academic General Discussions forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Grzegorz Kaczor
 
Posts: n/a

Default multiple locks - 06-10-2005 , 05:46 AM






Hello,

is it a mistake to lock the same object more than once? That is:

lock (this) {
lock (this) {
...
}
}

Is the syntax correct? This seems to work...

Regards,
Grzegorz Kaczor

Reply With Quote
  #2  
Old   
Alvin Bruney [MVP - ASP.NET]
 
Posts: n/a

Default Re: multiple locks - 06-11-2005 , 07:21 AM






It's not a multiple lock, it's a single lock. The runtime is smart enough to
realize that the calling thread already owns a lock on the reference, so one
lock is ignored. I'm not sure which lock though - possibly the inner.

--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @ www.lulu.com/owc, Amazon.com etc
"Grzegorz Kaczor" <grzegorz.kaczor (AT) cc (DOT) com.pl> wrote

Quote:
Hello,

is it a mistake to lock the same object more than once? That is:

lock (this) {
lock (this) {
...
}
}

Is the syntax correct? This seems to work...

Regards,
Grzegorz Kaczor



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.