thread::join() worked 10 hours and continues to work. But when I use detach() , it takes from 50 minutes to 1 hour and 10 minutes, and the flow stops working.
std::thread thr1(waitSignal); thr1.detach(); What am I doing wrong?
UPD
void waitSignal(){ while(1){ std::ofstream log("/tmp/debug.txt", std::ios_base::app | std::ios_base::out); log << time << " - thread\n"; sleep(10); } } int iniReceive(){ // some code to start receive std::thread thr1(waitSignal); thr1.detach(); return(1); } int main() { iniReceive(); while(1){ printf("main"); std::ofstream log("/tmp/debug.txt", std::ios_base::app | std::ios_base::out); log << time << " - MAIN\n"; sleep(60); } return(0); }
logobject from the loop so as not to perform creation / destruction on each iteration and use different files. Maybe there is a problem with simultaneous access to the file from different streams. - αλεχολυτ