《操作系统概念》第七版中的实验项目:生产者消费者问题
本程序中,main()函数需要 三个参数:主线程休眠时间;生产者线程数;消费者线程数
各线程的休眠等待时间是随机 的
程序代码:#include〈 stdio h>#include#define BUFFER_SIZE 5typedef int buffer_;itemstruct v{int ;i);buffer_item buffer[BUFFER_SIZE+1buffer_item front=0,re;ar=0HANDLE mutex , empty,full;int insert_i(ebuffer_item item){/*insert item into bufferreturn 0 if successful,otherwisereturn-1 indicating an error cond/tionif((rear+1 弘(BUFFER_SIZE+1)==front )return 1;buffer[rear=itemrear=(rear+1)%(BUFFER_SIZE+1);return 0;}int remove_item(buffer_item *item){/*remove an object from bufferplacing it in itemreturn 0 if successful,otherwisereutrn-1 indication an error condition */if(front == r)earreturn ;1* item=buffef front];front=(front+) % (BUFFER_SIZE+1);return 0;DWORD WINAPI producer (PVOID Param ) {int randlstruct v data=*(