terminate called without an active exception C/C++ Origin: Application & API C++11 and later Last updated 15 Oct 2026

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.

Exact message you may see terminate called without an active exceptionterminate called without an active exception Aborted (core dumped)std::terminate calledlibc++abi: terminating
Seen on: C/C++ GCC Clang

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() or detach() 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

  1. Call t.join() (or t.detach() if truly independent) before the thread object dies
  2. Use std::jthread in C++20
  3. Use an RAII wrapper so join happens even on exceptions

Detailed fix by platform

C++

  1. std::jthread worker([]{ /* work */ }); joins in its destructor
  2. For older standards write a small guard class whose destructor calls if (t.joinable()) t.join();

Code examples

Always join

cpp
#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

  1. Join — Is every thread joined or detached on all paths?
  2. Exceptions — Can an exception skip the join?
  3. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

AddressSanitizer: heap-buffer-overflow — C/C++: ==ERROR: AddressSanitizer: heap-buffer-overflow on address — READ/WRITE of size N (C/C++)AddressSanitizer: hea…call of overloaded is ambiguous — C++: error: call of overloaded 'f(int)' is ambiguous (C/C++)call of overloaded is…cannot declare variable to be of abstract type — C++: error: cannot declare variable 'x' to be of abstract type 'Shape' (pure virtual functions) (C/C++)cannot declare variab…pure virtual method called — C++: pure virtual method called — terminate called without an active exception (C/C++)pure virtual method c…std::bad_alloc — C++: terminate called after throwing an instance of 'std::bad_alloc' — what(): std::bad_alloc (C/C++)std::bad_allocterminate called after throwing an instance of — C++: terminate called after throwing an instance of 'std::out_of_range' — what(): vector::_M_range_check (C/C++)terminate called afte…undefined reference to pthread_create — C/C++: undefined reference to `pthread_create' — missing -pthread (also `dlopen`, `clock_gettime`) (C/C++)undefined reference t…terminate…

Explore the map of this error Full error map →

🧠 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.