Tom Ritchford
1 min readMar 9, 2023

--

Loss of liveness is hard to spot. Deadlocks are a special case of loss of liveness which are considerably easier to spot.

Deadlocks can be prevented by always taking locks in the same order, and are quite easy to detect in a language where it's easy to instrument locks.

In JVM languages, unfortunately considerably less so, because the locks are for some silly reason (yeah, yeah, I know why, it seemed a good idea when I was writing Java in the 90s) language features rather than a library, class or function you could intercept and instrument.

To be honest, I stopped using locks or mutexes when I left Java. The cost of taking a lock is simply too high, and the possibility of loss of liveness is always there.

Thread-safe queues are my go-to solution now. In C++ it is possible to make a thread-safe queue lock-free, though do not try to do this yourself. (I read through what seemed to be a great C++ lock-free queue, nodded my head, and then read a brutal rebuttal, and decided I shouldn't get into that business.)

--

--

No responses yet