473,626 Members | 3,305 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How did it dead lock?

Hi,
Sometimes my program stops and when I break it I see 2 threads both
waiting at a lock statement trying to lock the same object. If I look
up the call stack of these threads there aren't any other calls to lock
statements so I don't see how it's possible for anything to be locked.

Can anyone explain this to me?

Thanks

Mar 24 '06 #1
17 2510
Hi,

Is it possible that another thread other than the 2 you just mentioned
is holding the lock?

Brian

eu******@hotmai l.com wrote:
Hi,
Sometimes my program stops and when I break it I see 2 threads both
waiting at a lock statement trying to lock the same object. If I look
up the call stack of these threads there aren't any other calls to lock
statements so I don't see how it's possible for anything to be locked.

Can anyone explain this to me?

Thanks


Mar 24 '06 #2
Hello,

I don't think so, there aren't any other threads with source code
available
Brian Gideon wrote:
Hi,

Is it possible that another thread other than the 2 you just mentioned
is holding the lock?

Brian

eu******@hotmai l.com wrote:
Hi,
Sometimes my program stops and when I break it I see 2 threads both
waiting at a lock statement trying to lock the same object. If I look
up the call stack of these threads there aren't any other calls to lock
statements so I don't see how it's possible for anything to be locked.

Can anyone explain this to me?

Thanks


Mar 26 '06 #3
If you are trying to lock(this) then it can lead in to dead locks. Did
you try using SOS/Windbg to identify the dead lock and the stack trace?
Also post a smaple code.

Mar 26 '06 #4
Hello,

thanks for the help.

I am trying to lock(this) and that's where one of the threads stops.
The other thread stops while trying to lock the same object although
this time it isn't 'this'.
If I can't lock(this) then what should I do?

If it hangs again how do I use Windbg to help me?

Thanks again!

Mar 28 '06 #5
Here is reason as to why you shouldnt be using lock(this)
http://blogs.msdn.com/bclteam/archiv.../20/60719.aspx

and i guess you would have to learn how to use windbg to use to detect
dead locks. There are quite a lof of resources on the web.

Mar 29 '06 #6
<eu******@hotma il.com> wrote:
I am trying to lock(this) and that's where one of the threads stops.
The other thread stops while trying to lock the same object although
this time it isn't 'this'.
If I can't lock(this) then what should I do?


See http://www.pobox.com/~skeet/csharp/t...ckchoice.shtml

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 29 '06 #7


Naveen wrote:
Here is reason as to why you shouldnt be using lock(this)
http://blogs.msdn.com/bclteam/archiv.../20/60719.aspx


Complicating your code to defend against outside misuse is a loosing battle.

The solution to bad-outside-code is to let the bad-outside-coders accept
responsibility for their actions and develop their skill (if possible).
Not to spend unlimit development-time, readability and code-complexity,
up front.

--
Helge Jensen
mailto:he****** ****@slog.dk
sip:he********* *@slog.dk
-=> Sebastian cover-music: http://ungdomshus.nu <=-
Mar 29 '06 #8
Helge Jensen <he**********@s log.dk> wrote:
Naveen wrote:
Here is reason as to why you shouldnt be using lock(this)
http://blogs.msdn.com/bclteam/archiv.../20/60719.aspx


Complicating your code to defend against outside misuse is a loosing battle.

The solution to bad-outside-code is to let the bad-outside-coders accept
responsibility for their actions and develop their skill (if possible).
Not to spend unlimit development-time, readability and code-complexity,
up front.


If you buy that argument, would you suggest that everything should be
public, too?

Locking on explicit lock objects doesn't take unlimited development
time, nor does it impact readability or code complexity. Indeed, it
adds flexibility, and can allows more useful locking strategies, which
can detect deadlocks and offer timeouts, too:
http://www.pobox.com/~skeet/csharp/m.../locking.shtml

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 29 '06 #9


Jon Skeet [C# MVP] wrote:
If you buy that argument, would you suggest that everything should be
public, too?
Yes, I pretty much do. A side-benefit is much less complicated white-box
testing, since the "hiding" of implementation of state is only a hint,
not enforced.

Where possible, also outside computing, I prefer accountability to
prevention.

I admit that I occasionally declare members protected, when I know they
will change implmentation/signature within a short timeframe, or if they
are helper-functions local to the class -- since C# have no free
functions and these helpers aren't part of the behaiour of the class.

For code without security implications I believe in documenting the
risks and letting the user decide.

Prefixing with "_" can be enough documentation that this method or that
member is not for casual use, if that practice is well enough known in
the context.

I have yet to see a real example where private methods or properties do
any real good.
Locking on explicit lock objects doesn't take unlimited development
No, but it does require the programmer to do something more complicated.
Rules accumulate.

I don't particularly object to the use of an explicit lock-object. What
I don't like is stuff like:

"We strongly discourage the use of lock(this). Since other, completely
unrelated code can choose to lock on that object as well"

Which blanket states that a practice should be followed. I don't see any
other reason stated anywhere in the article.

If someone lock(x) on an object, what are they expecting?

lock(this) is preferrable in many cases, most notably those where a
data-structure internally need to lock, but callers also occasionally
need to mutually exclusively invoke multiple methods without intervention.
time, nor does it impact readability or code complexity. Indeed, it
adds flexibility, and can allows more useful locking strategies, which
I am well aware that lock(this) isn't the solution to all locking. But
it's not a bad practice that needs to be banned or workarounded either.
can detect deadlocks and offer timeouts, too:
And if those properties are needed, then by all means implement them.

I have come to prefer simplicity over almost anything, even correctness
upto a point. If it's complicated, it's probably wrong or bug-filled --
if it's simple then it may just be correct.

A very gifted co-worker and the C2 wiki: http://c2.com/cgi/wiki have
turned me from my old habits of closing everything I didn't see a use
for to a practice where I honestly present everything along with hints
about which risks are taken by using a specific level of knowledge about
the implementation.
http://www.pobox.com/~skeet/csharp/m.../locking.shtml


This link seems to be broken? i get 404.

--
Helge Jensen
mailto:he****** ****@slog.dk
sip:he********* *@slog.dk
-=> Sebastian cover-music: http://ungdomshus.nu <=-
Mar 29 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3837
by: chintalas | last post by:
Here when many users are trying to update the same table the dead lock situation is arising. I like to know how i can put a lock at record level in my table, so that the dead lock situation will not arise. pls send me a CC to kschintala@yahoo.com also
6
1450
by: Shanmugasundaram Doraisamy | last post by:
Dear Group, Is there a way to increase the time of Dead Lock? The default is set to 1000 msec. Regards, Shan. ---------------------------(end of broadcast)--------------------------- TIP 7: don't forget to increase your free space map settings
2
5856
by: shenanwei | last post by:
DB2 V8.2 on AIX, type II index is created. I see this from deadlock event monitor. 5) Deadlocked Connection ... Participant no.: 2 Lock wait start time: 09/18/2006 23:04:09.911774 ...... Deadlocked Statement: Type : Dynamic Operation: Execute
2
1958
by: Don | last post by:
How to stop a process which is running in a separate thread!!! I've got a class which performs some lengthy process in a background (separate) thread. And this lengthy process raises events regularly to inform the main thread of the progress (which is then displayed to the user). Since the event is raised from another thread, i've used me.Invoke() to update the ui properly. However, my problem is in cancelling the process. I need to...
4
4021
by: LamSoft | last post by:
It seems that my program is dead lock after running this sentence (bold) private delegate void updateBuildingDetailCallBack(String key, String Value); private void updateBuildingDetail(String key, String Value) { if (tabBuildings.Controls.InvokeRequired) { // This is not a UI thread, we cannot update the UI directly updateBuildingDetailCallBack callBack = delegate(String _key, String _Value)
0
1237
by: vaskarbasak | last post by:
Hi All, we have a large table having 60 lakhs and more data.so we are facing a problem when we are executing insert or update query. as a result our DB is very slow and sometimes we are facing deadlock , so it is not updated correctly. storage engine of this table is Inno DB. we want to access this table by creating views of that table.we want to execute insert , update on that view except using the main table. will it be a solution...
1
3256
by: Laurence | last post by:
Hi, DB2/400 seems not able to auto-rollback one of transactions while dead- lock occurred. I called the procecure QSYS.CREATE_SQL_SAMPLE for creating sample database, and used ISQL (STRSQL) & Navigator (Run SQL Scripts) to evaluate it:
0
8262
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8196
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8364
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7192
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6122
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5571
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.