单选题
1分
对于如下C语言程序void *th_f(void * arg){printf("Hello World");pthread_yield(0);}int ...
对于如下C语言程序
void *th_f(void * arg)
{
printf("Hello World");
pthread_yield(0);
}
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);
}
在上述程序中,pthread_yield的意义是( )。
void *th_f(void * arg)
{
printf("Hello World");
pthread_yield(0);
}
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);
}
在上述程序中,pthread_yield的意义是( )。
参考答案: C
参考解析: C【解析】题目程序在main()函数中调用pthread_create()函数创建一个新线程,设置新线程的入口函数为th_f,所以新线程创建后执行th_f函数,在th_f函数中输出Hello World,接着调用pthread_yield()函数,pthread_yield()函数是用来释放CPU来运行另外一个线程,所以答案选C选项。