C++: terminate called without an active exception — std::thread destroyed while joinable
A std::thread object was destroyed (or reassigned) while its thread was still running, so the C++ runtime called std::terminate.
terminate called without an active exceptionterminate called without an active exception Aborted (core dumped)std::terminate calledlibc++abi: terminating Meaning
Every std::thread must be either joined or detached before its destructor runs. Exiting main, returning early, or an exception unwinding past a live thread object all trigger it. Use std::jthread (C++20), which joins automatically, or wrap threads in an RAII guard.
Common causes
join()ordetach()never called on a thread- Early return or exception skipping the
join() - Assigning a new thread to a variable that still owns a running thread
- Thread stored in a container that is destroyed before the threads end
⚡ Quick fix
- Call
t.join()(ort.detach()if truly independent) before the thread object dies - Use
std::jthreadin C++20 - Use an RAII wrapper so join happens even on exceptions
Detailed fix by platform
C++
std::jthread worker([]{ /* work */ });joins in its destructor- For older standards write a small guard class whose destructor calls
if (t.joinable()) t.join();
Code examples
Always join
#include <thread>
#include <iostream>
int main() {
std::thread t([] { std::cout << "working\n"; });
// forgot t.join(); -> terminate called without an active exception
t.join(); // fix (or use std::jthread in C++20)
}How to diagnose
- Join — Is every thread joined or detached on all paths?
- Exceptions — Can an exception skip the join?
- Ownership — Is a thread variable overwritten?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- AddressSanitizer: heap-buffer-overflow C/C++: ==ERROR: AddressSanitizer: heap-buffer-overflow on address — READ/WRITE of size N
- call of overloaded is ambiguous C++: error: call of overloaded 'f(int)' is ambiguous
- cannot declare variable to be of abstract type C++: error: cannot declare variable 'x' to be of abstract type 'Shape' (pure virtual functions)
Most viewed in C/C++
- double free or corruption C/C++: free(): double free detected / double free or corruption (out) — Aborted (core dumped)
- undefined reference to C/C++: undefined reference to `function' — collect2: error: ld returned 1 exit status
- expected ';' before C/C++: error: expected ';' before 'x' — missing semicolon
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 15 Oct 2026