PracHub
QuestionsLearningGuidesInterview Prep
|Home/System Design/Box

Identify and fix deadlock in locked code

Last updated: Mar 29, 2026

Quick Overview

Identify and fix deadlock in locked code evaluates requirements, scale assumptions, API/data design, architecture, trade-offs, failure modes, and rollout in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

  • 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: Identify and fix deadlock in locked code evaluates requirements, scale assumptions, API/data design, architecture, trade-offs, failure modes, and rollout in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

Related Interview Questions

  • Explain and diagram your past system architecture - Box (hard)
  • Implement a leaky-bucket rate limiter - Box (hard)
  • Diagnose failures via SSH and large logs - Box (medium)
|Home/System Design/Box

Identify and fix deadlock in locked code

Box logo
Box
Aug 1, 2025, 12:00 AM
mediumSoftware EngineerOnsiteSystem Design
14
0

Identify and fix deadlock in locked code

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.

Constraints & Assumptions

  • Preserve the scope, facts, inputs, and requested outputs from the prompt above.
  • If the prompt leaves a detail unspecified, state a reasonable assumption before relying on it.
  • Keep the answer interview-ready: concise enough to present, but concrete enough to implement or evaluate.

Clarifying Questions to Ask Guidance

  • Clarify users, core use cases, read/write patterns, scale, latency, availability, and data retention.
  • State explicit assumptions before making sizing or architecture decisions.
  • Prioritize the functional path first, then address reliability, security, observability, and rollout.

What a Strong Answer Covers Guidance

  • A scoped requirements summary with concrete non-goals and success metrics.
  • API, data model, architecture, consistency, capacity, and operations.
  • Reasoned trade-offs among simple and scalable designs, including bottlenecks and failure modes.
  • A validation, monitoring, migration, and launch plan appropriate for the risk level.

Follow-up Questions Guidance

  • What breaks first at 10x traffic or data volume?
  • How would you degrade gracefully during dependency failures?
  • What metrics and alerts would prove the design is healthy after launch?

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

Your design canvas — auto-saved

PracHub

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

Product

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

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding 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.