I am very much confused with the usage of join() and detach() threads. Could anyone explain the logics and purpose of using both. Is it possible to use both functions in a same program?
When i run the below mentioned program the cout statment in check function is executed 5 times. whereas if i replace join() with detach() and run the same program, the cout statement in check function is executed only 4 times. Do anyone know the reason for this ?
#include <iostream>
#include <string>
#include <thread>
int *check(){ std::cout<<"entering check func"<<std::endl; return 0; }
int main() {
for(int i=0; i < 5; i++){
std::thread t(&check);
t.join();
} return 0;
}