Is this a dangerous locking pattern?
- by Martin
I have an enumerator written in C#, which looks something like this:
try
{
ReadWriteLock.EnterReadLock();
yield foo;
yield bar;
yield bash;
}
finally
{
ReadWriteLock.ExitReadLock();
}
I believe this may be a dangerous locking pattern, as the ReadWriteLock will only be released if the enumeration is complete, otherwise the lock is left hanging and is never released, am I correct? If so, what's the best way to combat this?