我有一个线程函数定义如下: exit() 和 pthread_exit() 有什么区别?
result = pthread_create(&consumer_thread, NULL, consumer_routine, &queue);
if (0 != result) {
fprintf(stderr, "Failed to create consumer thread: %s\n", strerror(result));
exit(1);
}
result = pthread_join(consumer_thread, &thread_return);
if (0 != result) {
fprintf(stderr, "Failed to join consumer thread: %s\n", strerror(result));
pthread_exit(NULL);
}
最佳答案
exit
函数正常终止进程,刷新缓冲区,调用 atexit
处理程序,等等。 pthread_exit
函数终止调用线程,仅当它是进程中的最后一个线程时才终止进程。否则,进程中的其他线程可以继续运行。
关于c - 主函数包含对 exit() 和 pthread_exit() 的调用。这两个调用在执行时的效果会有什么不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25925188/