登录
首页 » C/C++ » 读者写者问题

读者写者问题

于 2019-12-27 发布
0 94
下载积分: 1 下载次数: 1

代码说明:

说明:  1、定义一个数据缓存buffer及用于实现同步互斥的信号量。 2、定义一个读者函数: ?当有写者在占用buffer时,读者应该等待,直到写者不再使用该buffer。 ?当有其他读者在占用buffer时,读者可对buffer进行读取操作。 ?当buffer中有数据时,则从其中读取一个数据,并显示然后退出。 ?当buffer中没有数据时,应等待,直到buffer中有数据可读。 3、定义一个写者函数 ?当有读者在占用buffer时,写者应该等待,直到所有的读者都退出为止。 ?当有其他写者占用buffer时,该写者应该等待,直到占用buffer的写者退出为止。 ?当buffer有空闲时,写者应该在buffer中写入一个数据并退出。 ?当buffer满时,写者应该等待,直到buffer有空闲为止。 4、定义主函数,在其中可以任意创建读者与写者。 可根据用户输入创建读者或写者进程(线程)。(1. Define a data buffer and semaphores for synchronization and mutual exclusion. 2. Define a reader function: When a writer is occupying the buffer, the reader should wait until the writer no longer uses the buffer. When other readers occupy the buffer, they can read the buffer. When there is data in the buffer, read a data from it, display and exit. When there is no data in the buffer, wait until the data in the buffer is readable. 3. Define a writer function When a reader is occupying the buffer, the writer should wait until all readers quit. When other writers occupy the buffer, the writer should wait until the writer who occupies the buffer exits.)

文件列表:

main.cpp, 8587 , 2019-11-04

下载说明:请别用迅雷下载,失败请重下,重下不扣分!

发表评论

0 个回复

  • 696524资源总数
  • 103920会员总数
  • 65今日下载