结对小伙伴博客链接
实验报告封面
实验内容、步骤与体会
1、开发环境的配置同实验一
2、将实验代码拷贝到共享文件夹中
3、在虚拟机中编译代码
注:对于多线程相关的代码,编译时需要加-lpthread 的库
4、下载调试
在超级终端中运行可执行文件 pthread
实验过程的理解,实验指导书中知识点的理解
1.多线程的概念?为什么要提出多线程?
在一个程序中,这些独立运行的程序片断叫作“线程”(Thread),利用它编程的概念就叫作“多线程处理”。利用多线程,提高应用程序响应;使多CPU 系统更加有效;改善程序结构。
2.实验中控制两个进程顺利进行的关键是什么?
生产者首先要获得互斥锁,并且判断写指针+1 后是否等于读指针,如果相等则进入等待状态,等候条件变量notfull;如果不等则向缓冲区中写一个整数,并且设置条件变量为notempty,最后释放互斥锁。消费者线程与生产者线程类似,所以控制进程的关键为互斥锁。