Live n e s s H a z a rd s in Visual Studio .NET

Encoding Code 128B in Visual Studio .NET Live n e s s H a z a rd s
Live n e s s H a z a rd s
Draw Code 128 In .NET
Using Barcode generation for VS .NET Control to generate, create Code 128 image in Visual Studio .NET applications.
- Start +
Code-128 Scanner In .NET
Using Barcode recognizer for .NET framework Control to read, scan read, scan image in .NET framework applications.
Thread 1
Bar Code Encoder In .NET
Using Barcode maker for VS .NET Control to generate, create bar code image in Visual Studio .NET applications.
Waits for
Recognize Bar Code In .NET
Using Barcode reader for Visual Studio .NET Control to read, scan read, scan image in VS .NET applications.
Held by
Making Code128 In C#
Using Barcode printer for Visual Studio .NET Control to generate, create Code 128 image in .NET applications.
Thread 2
Draw Code 128 In .NET Framework
Using Barcode maker for ASP.NET Control to generate, create Code 128C image in ASP.NET applications.
)!:;
Making Code 128 In Visual Basic .NET
Using Barcode maker for VS .NET Control to generate, create Code 128 Code Set B image in Visual Studio .NET applications.
il J:
Data Matrix Generator In Visual Studio .NET
Using Barcode generator for .NET framework Control to generate, create ECC200 image in VS .NET applications.
Deadlock!
Bar Code Encoder In VS .NET
Using Barcode creator for Visual Studio .NET Control to generate, create bar code image in VS .NET applications.
J: C1l C" '<
Draw Bar Code In .NET
Using Barcode printer for .NET Control to generate, create bar code image in .NET framework applications.
Thread N
Encoding Code-39 In VS .NET
Using Barcode creator for .NET Control to generate, create ANSI/AIM Code 39 image in .NET applications.
+- Held by
2 Of 5 Industrial Creator In VS .NET
Using Barcode encoder for .NET Control to generate, create Standard 2 of 5 image in VS .NET applications.
Thread 3
Code 128 Code Set B Printer In .NET Framework
Using Barcode creation for ASP.NET Control to generate, create Code 128A image in ASP.NET applications.
FI G U R E 1 1 2 : A wait-gra p h illustrating a dead lock
Creating Bar Code In Java
Using Barcode generation for Java Control to generate, create bar code image in Java applications.
This is a relatively straightforward algorithm Even if you don't have a wait graph creation algorithm in play, you can use information available from a debugger and / or from crash dumps to create a graph to aid in debugging Even just reconstructing one on a whiteboard can be a helpful exercise for understanding difficult deadlocks Careful readers might have noticed a couple limitations with our algo rithm We don't ever create a true "graph," so why the name For simplicity's sake, we have limited our algorithm so that it handles threads waiting on a single lock only; that's acceptable because common lock kinds-such as Win32 C R ITICAL_S E CTIONs and CLR Mo n it o r s -only support single waits But for wait-any and wait-all style waits, the algorithm would need to be revised slightly Finally, creating a wait graph for reader /writer locks is not
Data Matrix ECC200 Generator In VB.NET
Using Barcode maker for VS .NET Control to generate, create DataMatrix image in .NET framework applications.
C h a pte r
Encoding Code-39 In C#
Using Barcode generator for .NET framework Control to generate, create Code-39 image in Visual Studio .NET applications.
C o n c u rre n cy H a z a r d s
Paint Code128 In Visual C#
Using Barcode creator for .NET Control to generate, create Code 128 Code Set A image in VS .NET applications.
shown and somewhat more complicated because a wait graph must include both shared-mode and exclusive-mode locks
Read EAN13 In Visual Studio .NET
Using Barcode recognizer for VS .NET Control to read, scan read, scan image in .NET framework applications.
Using Timeouts to Detect Deadlocks A less sophisticated technique for "detecting" deadlocks is to use timeouts when acquiring locks and wait ing on events Be forewarned : this technique is often misused It should be obvious that a deadlock is an error in the program that must be treated as a bug By the time a piece of code is labeled "done" it should be deadlock free, even if fancy techniques such as lock leveling haven' t been used Therefore, the use of timeouts to detect a deadlock is appropriate for debugging and testing, but not for inclusion in a production system By using a timeout during a synchronization wait-typically something ridiculously long like 5 seconds-you will be able to do any number of help ful things in response to a timeout This typically involves tracing some infor mation to a log, raising a debugger event (via De bugge r B r e a k in managed code), and / or even calling the E n v i ronment F a i l F a st or Termi nateProc e s s API t o bring down the process and allow a dump t o b e captured Which one is appropriate depends on your particular program, but this kind of checking is most often useful in debug builds and is best turned off in shipping bits Windows Vista Wait Chain Traversal (WCT) Windows Vista ships with a new set of Win32 APIs that fall under a single common feature, wait chain traversal, or WCT for short WCT is meant to enable debuggers to capture wait graphs, much like what was shown earlier, in a nonintrusive way Nonintrusive means that the debugged program need not be rewritten to support constructing an on demand wait graph: the WCT APIs gather and work with information already available in user-mode and the Windows kernel to produce a wait graph when requested to do so The WCT APIs also support a surprisingly rich set of wait kinds: ALPCs used for remote procedure calls, Win32 critical section acquisitions, mutex acquisitions, synchronous SendMe s sage calls for message queues, COM calls, and waits on process and thread handles WCT does not, however, support wait-any or wait-all style waits And it doesn't support managed code either, because it doesn't know about CLR monitors and other lock types This is because these locks are built out of custom synchronization mechanisms such as interlocked operations and events These practical limitations also mean
Make Barcode In C#
Using Barcode drawer for VS .NET Control to generate, create barcode image in Visual Studio .NET applications.
Llve n e s s H a z a rd s
Barcode Maker In Visual Studio .NET
Using Barcode printer for ASP.NET Control to generate, create barcode image in ASP.NET applications.
that WCT hasn't been integrated into popular debuggers such as Visual Studio yet The algorithm WCT uses is very much like the one shown before It looks at a particular thread and, if it is blocked, figures out on what object the thread is blocked, what thread owns that object, and so on WCT is declared in the wct h platform header file and exposed from the Adv a p i 3 2 library To use WCT, you'll need to first register some obscure call backs This is so WCT can retrieve state as needed to do with COM callbacks
VOID WINAPI Reg i st e rWa i t C h a i nCOMC a l l b a c k ( PCOG ETCAllSTAT E C a l lStateCa l l ba c k , PCOGETACTIVATIONSTATE ActivationStateC a l l b a c k );
Pass the addresses of o l e 3 2 d l l's CoGet C a l l S t a t e and CoGetAc t i v a t i o n State functions, respectively These are undocumented COM APls, so doing this feels hacky But it's all boilerplate and necessary for WCT to work Next, you must "open" a WCT session, which must be closed once you are done
HWCT WINAPI OpenTh readWa i t C h a i n Se s s ion ( DWORD F lags , PWAITCHAINCA l l BACK c a l l b a c k ); VOID WINAPI C l oseTh readWa itChainSe s s ion ( HWCT WctHand le ) ;
The Ope n T h r e a dWa i tC h a i n S e s s i o n returns a handle to the WCT session that can be used to close it later and to retrieve wait chain information from particular threads Retrieving a wait chain for a particular thread is done with GetTh readWa i tC h a i n
BOOl WINAPI GetTh readWa itCha i n ( HWCT WctHand l e , DWORD_PTR Context , DWORD F l a g s , DWORD Thread I d , lPDWORD NodeCou n t , PWAITCHAIN_NODE_I N F O NodeI nfoAr ray , lPBOOl I sCycle );
The Threadld parameter indicates which thread's chain is to be computed Context is only used for asynchronous retrieval and is an opaque value that