x
login about faq Site discussion (meta-askssc)

How to force a worker thread deadlock

I'd like to test a piece of software that detects deadlocks. There are several ways in which a deadlock can manifest in SQL Server. One of these is the 'worker thread deadlock'. Is there a simple way, via T-SQL, that could trigger such an event?

As per MSDN: A queued task waiting for an available worker thread can cause deadlock. If the queued task owns resources that are blocking all worker threads, a deadlock will result. For example, session S1 starts a transaction and acquires a shared (S) lock on row r1 and then goes to sleep. Active sessions running on all available worker threads are trying to acquire exclusive (X) locks on row r1. Because session S1 cannot acquire a worker thread, it cannot commit the transaction and release the lock on row r1. This results in a deadlock.

more ▼

asked Dec 07 '09 at 11:29 AM in Default

Robin gravatar image

Robin
33 1 1 1

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first
CREATE TABLE tablea (i int)
CREATE TABLE tableb (i int);

INSERT tablea SELECT 1
INSERT tableb SELECT 101;


-- in first session
BEGIN TRAN
UPDATE tablea SET i = 11 WHERE i = 1
WAITFOR DELAY '00:00:10'
UPDATE tableb SET i = 99 WHERE i = 101

COMMIT

-- in second session
BEGIN TRAN
UPDATE tableb SET i = 99 WHERE i = 101
WAITFOR DELAY '00:00:10'
UPDATE tablea SET i = 11 WHERE i = 1

COMMIT

For the deadlock notification I have turned on the trace flag(s) and I have a agent job that use a procedure to notify an operator tha a deadlock has occrus

http://ronsi-simple-thing.blogspot.com/2007/10/how-to-get-mail-notification-on-sql.html

more ▼

answered Dec 07 '09 at 11:39 AM

sp_lock gravatar image

sp_lock
8.1k 20 26 29

This isn't a worker thread deadlock, it is a lock resource deadlock. A worker thread deadlock would be caused when a worker locks a resource and then sleeps. While it sleeps other workers require the locked resource and are blocked holding up the workers. Meanwhile the sleeping process can't wake up because there are no workers available to bind to. You'd be lucky to trigger this kind of deadlock manually at demand. It would be very hard to reproduce.

Dec 14 '09 at 06:31 PM Jonathan Kehayias
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x32

asked: Dec 07 '09 at 11:29 AM

Seen: 5808 times

Last Updated: Dec 07 '09 at 11:29 AM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.