← Akuna Capital Interview Insights

Akuna Capital·Software Engineer·Technical Phone Screen·Senior

Senior
Jul 2026

Summary

Akuna Capital had me fix a broken C++ object pool under concurrency constraints. The scope was bigger than I expected for a single interview question, covering thread safety, RAII, shutdown semantics, and ABA prevention all at once.

Questions Asked (1)

Q1

You're given a buggy C++ object pool implementation with race conditions, double-free risks, and resource leaks under concurrent borrow/return. Refactor it into a correct, thread-safe object pool template with blocking borrow (optional timeout), safe return with duplicate rejection, RAII scoped handle, and clean shutdown. Assume C++17.

System DesignTechnical Trade-offsAlgorithms & Data Structures
Author's notes

This one took me a minute to even scope properly.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and identifying the core issues: race conditions, double-free, and leaks. Then design a thread-safe pool using mutex and condition variables, with RAII handles for automatic return and duplicate rejection via a borrowed set. Finally, discuss trade-offs like timeout handling, shutdown, and performance considerations.

Pro tip: Emphasize exception safety and clean shutdown: ensure that borrowed objects are returned even if exceptions occur, and that shutdown wakes all waiters and prevents new borrows. This shows you think about real-world robustness beyond just fixing the immediate bugs.

1. Clarify Requirements and Constraints

Ask about expected usage patterns, object lifetime, timeout semantics, and shutdown behavior. Confirm C++17 features and whether exceptions are enabled.

2. Design Core Data Structures and Synchronization

Use a mutex to protect a free list (e.g., std::vector or std::stack) and a set of borrowed pointers. Use condition variables for blocking borrow with optional timeout and for shutdown signaling.

3. Implement Borrow and Return with Safety

Borrow: wait on condition variable until an object is available or timeout/shutdown; pop from free list, insert into borrowed set, return RAII handle. Return: validate pointer is in borrowed set (reject duplicates), remove from set, push to free list, notify one waiter.

4. Implement RAII Handle and Shutdown

RAII handle holds pool reference and pointer; destructor calls return. Shutdown: set flag, notify all waiters, wait for all borrowed objects to be returned (or force cleanup), then destroy pool.

5. Discuss Trade-offs and Edge Cases

Cover performance (lock contention, object reuse), timeout precision, exception safety, and alternative designs (lock-free, per-thread pools). Mention testing strategies for concurrency.

Key Points to Mention

  • Use std::mutex and std::condition_variable for synchronization; avoid busy-waiting.
  • RAII handle ensures automatic return even on exceptions, preventing leaks.
  • Duplicate return rejection via a borrowed set (e.g., std::unordered_set) to prevent double-free.
  • Blocking borrow with optional timeout using wait_for and a predicate checking availability or shutdown.
  • Clean shutdown: signal all waiters, prevent new borrows, and ensure all objects are returned before destruction.
  • Exception safety: ensure mutex is unlocked and state is consistent if exceptions occur during borrow/return.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.