PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/System Design/Akuna Capital

Fix and harden an object pool

Last updated: Mar 29, 2026

Quick Overview

This question evaluates concurrent programming and systems-level C++ skills, including thread-safe generic template design, synchronization with mutexes/condition_variables and atomics, ABA mitigation, RAII-based resource management, fairness in wait queues, and safe shutdown semantics.

  • hard
  • Akuna Capital
  • System Design
  • Software Engineer

Fix and harden an object pool

Company: Akuna Capital

Role: Software Engineer

Category: System Design

Difficulty: hard

Interview Round: Take-home Project

Fix a buggy C++ object pool implementation. The current code exhibits races, double-free risks, and resource leaks under concurrent borrow/return. Refactor it into a correct, thread-safe object pool template. Requirements: - Provide borrow() that blocks (with an optional timeout) when the pool is empty, creating up to a max capacity; ensure fairness and avoid spurious wakeups. - Provide returnObject(obj) that safely returns an object; reject invalid or duplicate returns; optionally reset objects before reuse. - Enforce RAII with a scoped handle that automatically returns the object on destruction; handle must be movable but not copyable. - Ensure safe shutdown: destructor stops producers/consumers, wakes waiters, and releases resources without deadlocks. - Avoid busy-waiting; use std::mutex, std::condition_variable, and std::atomic correctly; prevent ABA issues (e.g., with generation counters). - Include minimal unit tests demonstrating correctness under multiple threads. Assume C++17 or later and document the complexity of core operations.

Quick Answer: This question evaluates concurrent programming and systems-level C++ skills, including thread-safe generic template design, synchronization with mutexes/condition_variables and atomics, ABA mitigation, RAII-based resource management, fairness in wait queues, and safe shutdown semantics.

Related Interview Questions

  • Implement a two-user communications handler - Akuna Capital (medium)
  • Design communication handler and exceptions - Akuna Capital (medium)
  • Design an order-matching engine - Akuna Capital (hard)
  • Design user communication functions - Akuna Capital (easy)
  • Design user communication manager APIs - Akuna Capital (medium)
Akuna Capital logo
Akuna Capital
Aug 10, 2025, 12:00 AM
Software Engineer
Take-home Project
System Design
4
0

Refactor a Buggy C++ Object Pool Into a Correct, Thread-Safe Template

Context

You are given a buggy C++ object pool that suffers from races, double-free risks, ABA problems, and resource leaks during concurrent borrow/return operations. Refactor it into a robust template that is correct under concurrency and safe to shut down.

Assume C++17 or later.

Requirements

  • Implement a generic, thread-safe object pool template for objects of type T.
  • Provide borrow() that blocks when the pool is empty and creates up to a maximum capacity.
    • Also provide an overload with a timeout (e.g., borrow_for(duration)).
    • Ensure fairness among waiters (FIFO) and avoid spurious wakeups.
  • Provide returnObject(obj) to safely return an object:
    • Reject invalid returns (wrong pool) and duplicate returns.
    • Optionally reset objects before reuse (configurable functor).
  • Enforce RAII via a scoped handle that returns the object automatically when destroyed.
    • Handle must be movable but not copyable.
  • Ensure safe shutdown:
    • Destructor stops producers/consumers, wakes waiters, and releases resources without deadlocks.
  • Avoid busy-waiting; use std::mutex, std::condition_variable, and std::atomic correctly.
  • Prevent ABA issues (e.g., generation counters per item).
  • Include minimal unit tests demonstrating correctness under multiple threads.
  • Document the time complexity of core operations.

Deliverables: A single self-contained C++17 implementation plus minimal unit tests and brief complexity notes.

Solution

Show

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More System Design•More Akuna Capital•More Software Engineer•Akuna Capital Software Engineer•Akuna Capital System Design•Software Engineer System Design
PracHub

Master your tech interviews with 7,500+ 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.