When can std::thread::join fail due to no_such_process

In what circumstances might that happen?

On *nix systems, it happens when you try to join a thread whose ID is not in the thread table, meaning the thread does not exist (anymore). This might happen when a thread has already been joined and terminated, or if your thread variable's memory has been corrupted.

Alternatively, what must I do to ensure that join() does not fail for that reason?

You might test std::thread::joinable(), but it might also fail1. Just don't mess with your thread variables, and you're good to go. Simply ignore this possibility, if you encounter such an error your program better core dump and let you analyse the bug.


1) By fail, I mean report true instead of false or the other way around, not throw or crash.