[英]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.