Ayende @ Rahien

Refunds available at head office

Challenge: Find the deadlock

Okay, there isn't much of a challenge here, but it is worth point out nevertheless:

image image

Comments

Aditya Caprihan
07/05/2008 02:33 PM by
Aditya Caprihan

If ‘ReleaseEnv’ is being executed on thread T1 and ‘AcquireEnv’ is being executed on thread T2 and both methods have been passed the same ‘fullPath’ and 'container.Release' returns 'true', there will be a deadlock in the following scenario:

T1 has a lock on ‘container’ and it releases its read lock and gets queued for a write lock. T2 already has a read lock and is now waiting to get a lock on ‘container’ (which T1 has a lock on). Since T1 is waiting for T2 to release its read lock and T2 is waiting on T1 to release the lock on ‘container’, both threads are waiting on each other and we have a deadlock.

Omer Mor
07/06/2008 03:55 AM by
Omer Mor

looks easy:

If T1 & T2 both enter ReleaseEnv() with an existing path, they'll both acquire read-lock, T1 will enter the monitor, and will try to upgrade to write-lock, but will block until T2 releases its read-lock.

Meanwhile T2 will block until T1 will leave the monitor.

So:

T1 waits for T2 (can't upgrade to writer),

T2 waits for T1 (can't enter monitor),

ergo: deadlock.

Omer.

Comments have been closed on this topic.