하나의 루프에서 취소하려는 약 6 개의 스레드 ID 배열이 있습니다. 이것은 이러한 스레드가 정리 후에 잘못된 메모리에 액세스하려고 시도하여 특정 seg 오류가 발생했기 때문입니다. 취소 유형을 asynchronous
으로 변경하면 스레드 취소 후에도 분할 오류가 계속 발생합니다. 취소 유형을 deferred
으로 변경하고 취소 지점을 pthread_join
으로 유지하면 2 회의 스레드 취소 후 코드가 결합에 의해 차단되고 종료되지 않습니다.루프에서 pthreads 취소하기
문제의 원인을 제시해주세요.
/* The cancel type is deferred and cancellation point is pthread_join. After 2
iterations, it is unable to come out of join and gets blocked. Here is the code:*/
for (int i=0;i<N_BATCH_THREADS;i++)
{
rc = pthread_cancel(g_batch_th[i]);
if(rc!=0)
{
fprintf(stderr,"Error in pthread cancel\n");
exit(1);
}
else
{
fprintf(stderr,"Thread cancelled successfully %d\n",g_batch_th[i]);
}
rc = pthread_join(g_batch_th[i],&status);
if(rc!=0)
{
fprintf(stderr,"Error in pthread join\n");
exit(1);
}
else
{
fprintf(stderr,"Return from pthread join successful %d\n",g_batch_th[i]);
}
if(status != PTHREAD_CANCELED)
{
fprintf(stderr,"Unexpected thread status \n");
exit(1);
}
}
해당 코드 조각을 추가 할 수 있습니까? –