Detect deadlocks using error codes