What Does Detaching a Thread Do?
When You Detach Thread It Means That You Don't Have to Join() It Before Exiting Main(). Thread Library Will Actually Wait for Each Such Thread Below-Main, but...
When you detach thread it means that you don't have to join() it before exiting main() . Thread library will actually wait for each such thread below-main, but you should not care about it. detach() is mainly useful when you have a task that has to be done in background, but you don't care about its execution.
What happens when you detach a thread?
Detaching Threads
Separates the thread of execution from the thread object, allowing execution to continue independently. Any allocated resources will be freed once the thread exits.
Can a detached thread be joined?
A detached thread cannot be joined (in the sense of std::thread::join() ). You can wait for results from detached threads (e.g. via a future from std::packaged_task , or by a counting semaphore or a flag and a condition variable), but that doesn't guarantee that the thread has finished executing.