[10][10][单选]有如下 C 语言程序
void * th_f(void * arg) { printf("Hello World"); } int main(void) { pthread_t tid; st = pthread_create(&tid, NULL, th_f, NULL); if(st == 0) printf("Oops, I can not createthread\n"); exit(NULL); }
针对上述程序,下列叙述中哪一个是正确的
线程 th_f 运行中出现错误
线程 th_f 运行后等待一个特定的线程退出
线程 th_f 运行后主动释放 CPU 给其他线程
线程 th_f 运行后退出
答案
线程 th_f 运行后退出
解析
pthread_create(&tid, NULL, th_f, NULL)创建线程后,运行该线程。只有一个 printf 函数调用语句,所以线程会执行完指令后退出,线程 th_f 运行后主动退出。故本题答案选择 D 选项。涉及考点为第 3 章进程线程模型。
转载请注明出处。