Design thread-safe APIs

Design thread-safe APIs in C++ — with the four heights of help laid out: do it now, make it easier for the next person to accept, work out the right move when you are stuck, and learn the pattern so it stops coming back.

4prompt heights
Open it in the interactive atlas →

The four heights

The same task, four distances: today's deadline, the next reviewer, the stuck moment, the pattern.

Execute — do the immediate task

+
I'm delivering a public API for concurrent use: expose a small set of functions that let callers…
I'm delivering a public API for concurrent use: expose a small set of functions that let callers create, join, and cancel tasks without data races. Require the caller to pass a const reference for read-only data and a unique_ptr for ownership transfer. Validate arguments and document which functions lock which internal mutex. Sign the header and implementation, run the unit tests that spawn 100 threads, and fix any race failures before code review on Thursday.

Improve — make it easier to accept

+
Before I publish this API to the team, make it obvious which calls are safe from any thread and…
Before I publish this API to the team, make it obvious which calls are safe from any thread and which must be called from a single thread. Put the thread-safety guarantees at the top of the header, move ownership-transfer signatures up front, show the locking hierarchy in a small diagram, and flag any functions that may block for more than 50 ms. Also suggest a minimal example that demonstrates safe concurrent use for the common case.

Decide — diagnose the stuck moment

+
I merged the API change; reviewers are saying the design looks clean but CI shows intermittent data…

I just merged a change and CI reported intermittent data races.

I merged the API change; reviewers are saying the design looks clean but CI shows intermittent data races in integration tests that spawn 200 tasks. I cannot reproduce locally and I don't know which call sites are breaking the locking rules. I'm afraid we'll ship an API that causes subtle corruption. What are the most likely causes, what targeted diagnostics should I add to find the culprit, and what's the safest short-term rollback or mitigation so the branch can be stabilized?

Become — change the pattern

+
Over the last six months we keep landing 'small' API tweaks that later cause concurrency bugs and…

Repeated race bugs appear after “minor” API changes.

Over the last six months we keep landing 'small' API tweaks that later cause concurrency bugs and long debug cycles. We lose time arguing about ownership and locking at review. Which habits should I instill to stop this pattern: how to structure headers, what review checklist items catch the common mistakes, and a lightweight testing practice that prevents these regressions without doubling review time?

Next to this one

Other programming language work people do in C++.

Every task here came from the work, not from a feature list — which is why the prompts name what you want done and never the button that does it. The tool changes; the work does not.
Copyright © LLOS.ai · 2026 — original pedagogy, voice, and design — all rights reserved.

The rest of the map

Same library, five ways in.