Earlier today, I was debugging something like this:
class Foo {
void AccessCriticalSection() {
try {
if (IO.File.Exists("\\path\to\lock.txt")
throw new Exception();
System.IO.File.Create("\\path\to\lock.txt");
criticalSection();
} catch (Exception ex) {
}
}
void CriticalSection() {
System.IO.File.Delete("\\path\to\lock.txt");
}
}
He doesn’t even understand how terrible this is ... but he is essentially trying to use a file called lock.txtas his mutex. The operation is not atomic, other processes simply do not go through the critical section if another process uses it (they are intended to continue after the lock is released, if you can believe it), etc. Etc. Obviously it should be fixed.
? , , (.. , , , private final static Object lock = new Object(); )