* 线程控制函数示例 编写程序threadtest.c,能够创建一个线程,该线程显示3次字符串“This is a pthread”,父进程显示3次字符串“This is the main process”。 步骤1:选择编辑程序编辑源文件threadtest.c,其源码如下所示。 #include stdio.h #include pthread.h void thread(void) { int i; for (i=0;i3;i++) printf(This is a pthread.\n); } * 线程控制函数示例 int main(void) { pthread_t id; int i,ret; ret=pthread_create(id,NULL,(void *) thread,NULL); if (ret!=0) { printf (Create pthread error!\n); exit (1); } for (i=0;i3;i++) printf(This is the main process.\n); pthread_join(id,NULL); return(0); } * 线程控制函数示例 步骤2:

文档评论(0)

1亿VIP精品文档

相关文档