We must use recursive mutexes if we want to lock multiple times in the same thread

This fixes deadlock issues seen on Linux, at least.