[真2][10][单选]对于如下 C 语言程序
- void *th_pg(void *arg)
- {
- printf("Hello World");
- pthread_yield(0);
- }
- int main(void)
- {
- pthread_t tid;
- int st1, st2;
- st1 = pthread_create(&tid, NULL, th_pg1, NULL);
- if (sta== 0)
- printf("Oops, I can not create thread1\n");
- st2 = pthread_create(&tid, NULL, th_pg2, NULL);
- if (st2 == 0)
- printf("Oops, I can not create thread2\n");
- exit(NULL);
- }
在上述程序中,pthread_yield 的意义是
线程 th_pg1 和 th_pg2 运行后主动退出
线程 th_pg1 和 th_pg2 运行后主动释放 CPU 给其他线程
线程 th_pg1 和 th_pg2 运行后等待一个特定的线程退出
线程 th_pg1 和 th_pg2 运行后成为僵尸线程
答案
线程 th_pg1 和 th_pg2 运行后主动释放 CPU 给其他线程
解析
pthread_create(创建线程后,运行线程函数,线程 th_pg1 和 th_pg2 分别调用了 pthread_yield(,线程在执行过程中主动让出 CPU 给其他线程,故选择 B 选项。
转载请注明出处。