Sunday, March 13, 2011

deadlocks problem

Today i solve a problem with deadlocks on middle size code-base.
The problem that in this code base the usages of lock implemented by csharp keyword lock (without any timeout system).

I add new class from this site : lock with timeout.
After this i generate search and replace in visual studio 2008 using regexp.

find: lock[ ]*\({[^\)\n]*}\)
replace: using(TimedLock.Lock(\1))

This regexp replacing all lock occurrences (that not commented out) with new timeout locks.
example
lock(myLock)
to
using(TimedLock.Lock(myLock))