Ads by The Lounge
My name is Oren Eini and you can reach me by: Email or MSN: Ayende@ayende.com Cellular: (972) 052-548-6969 About me
Challenge: Find the deadlock
Okay, there isn't much of a challenge here, but it is worth point out nevertheless:
Print | posted on Saturday, July 05, 2008 9:36 AM
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.
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.
Powered by: Copyright © Ayende Rahien