[英]Not using pthread_detach or pthread_join, will not clean up the resources for other newly created threads?
Below is my code snippet.
int main ( )
{
some instructions;
while ( 1 )
{
/* Block 1 : Starts*/
if ( selection == 1 )
{
ret = pthread_create ( &tid, NULL, &select_n_process_req, NULL );
if ( ret != 0 )
{
printf ("Error Creating Thread");
}
}
/* Block 1 : Ends*/
/* Block 2 : Starts*/
printf ("Sleeping for [%d]", retry_time * 60 * 60);
for ( i = 0; i < retry_time * 60 * 60; i++ )
{
if ( stop_flag == 1 )
{
printf ("Process Stopped\n");
break;
}
sleep ( 1 );
}
/* Block 2 : ENDS*/
}
some instructions;
return SUCCESS;
}
int select_n_process_req ( void )
{
some instructions;
return SUCCESS;
}
代码说明:
题:
谢谢。
您必须调用pthread_join (从父线程)或pthread_detach ,或者通过将其他属性传递给pthread_create来以分离状态创建线程。 看到这里: http : //man7.org/linux/man-pages/man3/pthread_create.3.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.