多线程同步与等待机制实验手册.pdfVIP

  • 0
  • 0
  • 约1.37万字
  • 约 10页
  • 2026-09-20 发布于北京
  • 举报

表格

{

边框‑塌陷:

坍陷;

}

表格,

th,

td

{

边框:

1px

固定

#000;

}

可以看到程执行函数中打印出了主函数中赋值的结构体,即把这个结构体传递给了线程执行函数。

实验2-5-2线程等待

•实验目的:

通过使用

pthread_join

系统调用,理解线程和进程的执行顺序

•实验要求:

编写应用程序,创建一个线程,进程需要等待该线程结束才能继续执行。

•实验器材:

软件:

安装了

RHEL5

VMware

虚拟机

硬件:

一台

PC

•实验代码与分析:

实验代码

2‑5‑2

thread_join.c

#include

pthread.h

#include

unistd.h#

includestdio.h

void

*thread(void

*str)

{

int

i;

for

(i

= 0;

i

 3;

i++)

{

sleep(2);

printf(This

in

the

thread:%d,i);

}

return

NULL;

int

main()

{pthread_t

pth;

int

i;

/*

创建线程并执行线程执行函数

*/

int

ret

pthread_create(pth,NULL,thread,NULL);

printf(The

main

文档评论(0)

1亿VIP精品文档

相关文档