pthread lock failed: Resource deadlock avoided