Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2007

Tip: Looking for answers? Try searching our database.

why no dead lock for this one?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DAXU@HOTMAIL.COM - 05 Jul 2007 16:17 GMT
Hello,
I did this as a test code:

public class test{
....
....
public void test(int i)

{
lock(this)
{
if (i>10)
{
i--;
test(i);
}
}
}
}

I thought that when I run test(11), it should give me a deadlock as
first it asks to lock the instance of the class, then as i is bigger
than 10, it will go deeper and try to lock the instance of the class
again, as it has been locked, then it should just wait there for ever.

But it went through without any deadlock, can someone tell me what is
wrong with my understanding?

Many Thanks
Jerry
DAXU@HOTMAIL.COM - 05 Jul 2007 16:23 GMT
lock ensures that one thread does not enter a critical section of code
while another thread is in the critical section.
I should create another thread to test it, so not a valid test anyway.

On 5 Jul, 16:17, D...@HOTMAIL.COM wrote:
> Hello,
> I did this as a test code:
[quoted text clipped - 27 lines]
> Many Thanks
> Jerry
Alvin Bruney [MVP] - 05 Jul 2007 16:34 GMT
See spec 8.12 which reads in part (edited for clarity):
lock ensures that one thread does not enter a critical section while another
thread is in the critical section of code.

...

While a mutual-exclusion lock is held, code executing in the same execution
thread can also obtain and release the lock. However, code executing in
other threads is blocked from obtaining the lock until the lock is released.

Signature

Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
https://www.microsoft.com/MSPress/books/10933.aspx
OWC Black Book www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley

> Hello,
> I did this as a test code:
[quoted text clipped - 26 lines]
> Many Thanks
> Jerry

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.