I have a stream named mainloop
i.e.
int run_mainloop;
void* mainloop(void* param)
{
while(run_mainloop)
{
}
return 0;
}
The thread starts from a function with a name client_open, i.e.
int client_open()
{
run_mainloop = 1;
return pthread_create(&thread, NULL, mainloop, NULL);
}
However, in mainloop, if the initialization of local variables failed, I need to immediately report client_openthe beginning of the exit.
pthread_joinnot suitable as it is blocking and I cannot have a block client_open. Had to wait a short time before returning, it would be okay.
How can I do this nicely without using pthread_join, which will block. I want to get a return code.
source
share