PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/System Design/Box

Identify and fix deadlock in locked code

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of concurrency control, deadlock diagnosis, and mutex-based synchronization in multithreaded programs. It is commonly asked to assess reasoning about inter-thread interactions and trade-offs in system design, is categorized under System Design and concurrent programming, and primarily tests practical application of debugging and mitigation strategies rather than purely conceptual theory.

  • medium
  • Box
  • System Design
  • Software Engineer

Identify and fix deadlock in locked code

Company: Box

Role: Software Engineer

Category: System Design

Difficulty: medium

Interview Round: Onsite

You are given a multithreaded code snippet that acquires multiple locks and sometimes deadlocks. Identify the precise deadlock scenario and propose code changes to prevent it. Discuss techniques such as consistent lock ordering, using try-lock with backoff, timeouts, or changing lock granularity, and analyze trade-offs.

Quick Answer: This question evaluates understanding of concurrency control, deadlock diagnosis, and mutex-based synchronization in multithreaded programs. It is commonly asked to assess reasoning about inter-thread interactions and trade-offs in system design, is categorized under System Design and concurrent programming, and primarily tests practical application of debugging and mitigation strategies rather than purely conceptual theory.

Related Interview Questions

  • Explain and diagram your past system architecture - Box (hard)
  • Diagnose failures via SSH and large logs - Box (medium)
  • Implement a leaky-bucket rate limiter - Box (hard)
Box logo
Box
Aug 1, 2025, 12:00 AM
Software Engineer
Onsite
System Design
11
0

Multithreaded Deadlock: Diagnose and Fix

Context

You have concurrent code that acquires multiple locks and occasionally deadlocks. The underlying issue is likely inconsistent lock acquisition order across threads. The goal is to identify the exact deadlock scenario and propose robust fixes. Assume two shared resources protected by two locks (A and B), and that different threads may acquire them in different orders.

Example Code (C++)

std::mutex mA;
std::mutex mB;

void thread1() {
  std::unique_lock<std::mutex> lA(mA);
  // ... do some work
  std::unique_lock<std::mutex> lB(mB);
  // critical section using A and B
}

void thread2() {
  std::unique_lock<std::mutex> lB(mB);
  // ... do some work
  std::unique_lock<std::mutex> lA(mA);
  // critical section using B and A
}

Tasks

  1. Identify the precise deadlock scenario (the interleaving leading to deadlock).
  2. Propose code changes to prevent deadlocks.
  3. Discuss techniques and trade-offs: consistent lock ordering, try-lock with backoff, timeouts, and changing lock granularity.

Solution

Show

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More System Design•More Box•More Software Engineer•Box Software Engineer•Box System Design•Software Engineer System Design
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.