代码如下:
pthread_t *threads;
pthread_attr_t pta;
threads = (pthread_t *) malloc(sizeof(pthread_t) * NumThreads);
pthread_attr_init(&pta);
for(i=0; i<NumThreads; i++) {
pthread_create(&threads[i], &pta, (void*(*)(void*))Addup, (void*)(i+1));
}
for(i=0; i<NumThreads; i++) {
ret_count = pthread_join(threads[i], NULL);
}
pthread_attr_destroy(&pta);
free(threads); // Is this needed?
那么,有必要free(threads)
吗?是否pthread_attr_destroy(&pta)
释放内存资源?