Re: Am I using ThreadPool the right way?
- From: Peter Duniho <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Wed, 24 Oct 2007 10:46:32 -0700
Ricardo Vazquez wrote:
[...]
But, as I said, I'm new to .net and Visual Studio 2005...
What is it the way to debug a deadlock? Any guidelines, web links, orientation, detailed explanation...? :-)
First, you'll need to be using a retail version of Visual Studio. It is possible to debug deadlocks and other threading issues in the Express version, but it's not something I'd recommend for someone unfamiliar with the general techniques of dealing with thread issues in the first place, since Express doesn't provide any direct way to get at the individual threads in the debugger.
So, assuming you have a retail version of VS, the next step is to run your application under the debugger until it gets stuck (or attach the VS debugger to a process running your application after it gets stuck).
At that point, use the Break command to stop execution of your program. Once the process has been interrupted, you can then use the Threads drop-down in the Debug toolbar to examine the state of each thread. It will allow you to switch from one thread to another, with the source view, stack trace, local variables, etc. being updated according to the current thread.
Some of the thread will be irrelevant, and may not even include any of your own code (all of the code in the stack trace will be "external"). You'll be looking for threads that are stopped on a statement that waits for some resource, to identify which threads are involved in the deadlock and why they are waiting.
At some point, you should come across at least two threads that are waiting, each of which are waiting on a different resource, but in each case a resource being held by some other thread that is also waiting. That's your deadlock.
Once you've identified that, then you need to figure out what in your design led to the bug where you have that circular resource acquisition going on and fix that. Depending on your experience level that in and of itself could be a challenge, but regardless you need to first identify the problem for that to even be an option.
Pete
.
- References:
- Am I using ThreadPool the right way?
- From: Ricardo Vazquez
- Re: Am I using ThreadPool the right way?
- From: Peter Duniho
- Re: Am I using ThreadPool the right way?
- From: Ricardo Vazquez
- Am I using ThreadPool the right way?
- Prev by Date: Math
- Next by Date: Re: C#- coordinate system, drawing
- Previous by thread: Re: Am I using ThreadPool the right way?
- Next by thread: Re: Am I using ThreadPool the right way?
- Index(es):
Relevant Pages
|