单选题
1分
有如下C语言程序void * th_f(void * arg){printf("Hello World");pthread_join(2);}int main(void){pthread_t tid;...
有如下C语言程序
void * th_f(void * arg)
{
printf("Hello World");
pthread_join(2);
}
int main(void)
{
pthread_t tid;
int st;
st = pthread_create(&tid, NULL, th_f, NULL);
if(st==0)
printf("Oops, I can not createthread\n");
exit(NULL);
}
针对上述程序,下列叙述中哪一个是正确的?
void * th_f(void * arg)
{
printf("Hello World");
pthread_join(2);
}
int main(void)
{
pthread_t tid;
int st;
st = pthread_create(&tid, NULL, th_f, NULL);
if(st==0)
printf("Oops, I can not createthread\n");
exit(NULL);
}
针对上述程序,下列叙述中哪一个是正确的?
参考答案: B
参考解析: B【解析】pthread_create(&tid, NULL, th_f, NULL);创建线程后,运行该线程,th_f线程中调用了pthread_join(2);。线程th_f运行后等待该线程退出后退出。故选择B选项。