[9][10][单选]有如下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 cannot createthread\n"); exit(NULL); }
针对上述程序,下列叙述中哪一个是正确的
线程th_f运行后自动退出
线程th_f运行后等待一个特定的线程退出
线程th_f运行后去将CPU给其他线程
线程th_f运行后进入等待态
答案
线程th_f运行后去将CPU给其他线程
解析
pthread_create(&tid, NULL, th, NULL):创建线程后,运行该线程,th线程中调用了pthread_yield(0)。线程th运行后等待该线程退出后接起自己,将CPU让给其他线程。故本题答案选择C选项。涉及考点为第3章进程线程模型。
转载请注明出处。