Working around MySQL error “Deadlock found when trying to get lock; try restarting transaction”

If you are using InnoDB or any row-level transactional RDBMS, then it is possible that any write transaction can cause a deadlock, even in perfectly normal situations. Larger tables, larger writes, and long transaction blocks will often increase the likelihood of deadlocks occurring. In your situation, it’s probably a combination of these. The only way … Read more

Why does parallel stream with lambda in static initializer cause a deadlock?

I found a bug report of a very similar case (JDK-8143380) which was closed as “Not an Issue” by Stuart Marks: This is a class initialization deadlock. The test program’s main thread executes the class static initializer, which sets the initialization in-progress flag for the class; this flag remains set until the static initializer completes. … Read more

Re-entrant locks in C#

No, not as long as you are locking on the same object. The recursive code effectively already has the lock and so can continue unhindered. lock(object) {…} is shorthand for using the Monitor class. As Marc points out, Monitor allows re-entrancy, so repeated attempts to lock on an object on which the current thread already … Read more

Recursive Lock (Mutex) vs Non-Recursive Lock (Mutex)

The difference between a recursive and non-recursive mutex has to do with ownership. In the case of a recursive mutex, the kernel has to keep track of the thread who actually obtained the mutex the first time around so that it can detect the difference between recursion vs. a different thread that should block instead. … Read more