We use optional cookies for analytics and affiliate attribution. Essential cookies and marketing measurement are always on. Read our privacy policy

We just launched our Black Friday sale. You can use code BF2026 to get 25% off all subscriptions, valid until Nov 30th. There is a limit of 100 redemptions.

Logo

Implement std::jthread

What this preview is

Implement std::jthread is a hard quant coding problem on concurrency in Cpp.

Difficulty
Hard
Topic
Concurrency
Discipline
Quant development
Language
Cpp

Implementing std::jthread with stop-token support in C++

This is a hard coding problem that tests your ability to design and implement a modern C++ synchronization primitive from first principles. It combines thread lifecycle management, callable-type introspection, and lock-free state coordination—all of which appear in systems code at trading firms and infrastructure teams.

The problem requires you to build a joinable thread wrapper that automatically joins (and can cancel) on scope exit, avoiding the silent termination that can occur with raw std::thread. Key challenges include detecting whether a callable accepts a stop token at compile time, managing the transition from active to canceled state without locks, and ensuring thread safety across destruction, detachment, and external cancellation requests.

  • SFINAE or std::invoke_result for callable type checking
  • Atomic flags and memory ordering for lock-free synchronization
  • Thread lifecycle: construction, detach, join, and scope-based cleanup
  • Implicit conversions and move semantics restrictions

Unlock full access to getcracked

Join to unlock this problem, detailed solutions, and our complete library of quant finance interview prep.