简单的多线程程序 下面的例子是一个多线程的程序,在主程序中创建一个线程 循环输出一段文字,主线程和子线程分时使用CPU 复习要点:时间片的概念 多线程的概念 CPU调度 #include <stdio.h> #include <pthread.h> void thread(void) { int i; for(i=0;i<100;i++) printf("This is in fun_thread %d/n",i); } int main() { pthread_t tid; int i,rtn; //create a ew pthread in the main process //they will share the cpu time shot rtn=pthread_create(&tid,NULL,thread,NULL); if(rtn!=0) { printf("create thread error!/n"); exit(1); } for(i=0;i<100;i++) printf("This is in main_thread %d/n",i); pthread_join(tid,NULL); return 0; }