#include
#include
/*信号量的定义-操作系统兔子吃草-操作系统 - IMDN开发者社群-imdn.cn" />
#include#include/*信号量的定义,它是负责协调各个线程,以保证它们能够正确、合理的使用公共资源。用于控制进程间的同步与互斥*/ typedefHANDLESemaphore; Semaphoreg_semBuffer,g_semGlass,g_mutex;//mutex为互斥锁 //利用Windows下的API函数(视窗操作系统应用程序接口)来定义P、V操作 #defineP(S)WaitForSingleObject(S,INFINITE)#defineV(S)ReleaseSemaphore(S,1,NULL)#definerate1000 #defineCONSUMER_NUM4//消费者个数#definePRODUCER_NUM4//生产者个数#defineBUFFER_NUM4//缓冲区个数 char*thing[4]={"glass1","glass2","glass3","glass4"};//公共的队列缓冲区 structBuffer{ intproduct[BUFFER_NUM]; intfront,rear; }g_buf;//兔子线程DWORDWINAPIRabbit(LPVOIDpara) { inti=*(int*)para;//第i只小白兔&-IMDN开发者社群-imdn.cn">
#include#include/*信号量的定义,它是负责协调各个线程,以保证它们能够正确、合理的使用公共资源。用于控制进程间的同步与互斥*/ typedefHANDLESemaphore; Semaphoreg_semBuffer,g_semGlass,g_mutex;//mutex为互斥锁 //利用Windows下的API函数(视窗操作系统应用程序接口)来定义P、V操作 #defineP(S)WaitForSingleObject(S,INFINITE)#defineV(S)ReleaseSemaphore(S,1,NULL)#definerate1000 #defineCONSUMER_NUM4//消费者个数#definePRODUCER_NUM4//生产者个数#defineBUFFER_NUM4//缓冲区个数 char*thing[4]={"glass1","glass2","glass3","glass4"};//公共的队列缓冲区 structBuffer{ intproduct[BUFFER_NUM]; intfront,rear; }g_buf;//兔子线程DWORDWINAPIRabbit(LPVOIDpara) { inti=*(int*)para;//第i只小白兔& - IMDN开发者社群-imdn.cn">
于 2022-05-23 发布
文件大小:1.15 MB
0 124
#include "stdafx.h"
#include
#include
#include
/*信号量的定义,它是负责协调各个线程, 以保证它们能够正确、合理的使用公共资源。 用于控制进程间的同步与互斥*/
typedef HANDLE Semaphore;
Semaphore g_semBuffer,g_semGlass, g_mutex; //mutex 为互斥锁
// 利用 Windows 下的 API 函数(视窗操作系统应用程序接口)来定义 P、V 操作
#define P(S) WaitForSingleObject(S,INFINITE)
#define V(S) ReleaseSemaphore(S,1,NULL)
#define rate 1000
#define CONSUMER_NUM 4 // 消费者个数
#define PRODUCER_NUM 4 // 生产者个数
#define BUFFER_NUM 4 // 缓冲区个数
char *thing[4]={"glass1","glass2","glass3","glass4"};
//公共的队列缓冲区
struct Buffer
{
int product[BUFFER_NUM];
int front,rear;
}g_buf;
//兔子线程
DWORD WINAPI Rabbit(LPVOID para)
{
int i =*(int*)para; //第 i 只小白兔&
下载说明:请别用迅雷下载,失败请重下,重下不扣分!
生产者和消费者
生产者和消费者实验代码,主要是为了应付操作系统实验而选择的代码。希望可以帮助到大家顺利完成实验吧,不挂科。代码有相应的注释,大家应该看得懂。代码的环境是VC6.0就可以编译,很方便。好了,大家有兴趣就下载来用用吧。
2022-12-01 10:45:03下载
积分:1
php技术开源系 统
http://www.codeforge.cn/article/edithttp://www.codeforge.cn/article/edithttp://www.codeforge.cn/article/edithttp://www.codeforge.cn/article/edit
2022-09-22 09:35:04下载
积分:1
Synchronous multi
多进程同步方通过研究Linux 的进程机制和信号量实现生产者消费者问题的并发控制.法解决生产者-消费者问题-Synchronous multi-process Linux through the process of research the mechanisms and signal volume producers realize concurrency control on consumer issues. Method to solve the producer- consumer issues
2023-02-20 19:00:04下载
积分:1
一个简单实用的嵌入式操 作 系 统 ,实现了嵌入式操 作 系 统 的基本模块:内存管理、系 统 调度
、系 统 调用等。...
一个简单实用的嵌入式操作系统,实现了嵌入式操作系统的基本模块:内存管理、系统调度
、系统调用等。-One simple embedded OS
2022-02-15 01:39:17下载
积分:1
Linux共享内存share memory通信机制的内核实现,可以为内核线程间通信提供机制...
Linux共享内存share memory通信机制的内核实现,可以为内核线程间通信提供机制-Linux shared memory communication mechanism share memory kernel realized, kernel threads can provide the mechanism for communication
2022-04-09 20:03:15下载
积分:1
操 作 系 统 下的仿真操 作 系 统 开发的替换页面
用VC开发的模拟操作系统的页面置换-VC simulation of the operating system developed by the replacement pages
2022-01-23 10:19:20下载
积分:1
操 作 系 统 的内存管理,包括自己的alloc和free函数
操作系统的内存管理,包括自己的alloc和free函数-operating system memory management, including its own alloc and free function
2022-01-23 11:17:04下载
积分:1
dining philosophers problem Java version
哲学家进餐问题Java版-dining philosophers problem Java version
2022-06-16 20:08:38下载
积分:1
文件管理模拟系 统 设计报告
文件管理模拟系统设计报告-document management simulation system design report
2022-05-18 19:44:44下载
积分:1
讲的很详细,希望对大家有用,一共有三部分
讲的很详细,希望对大家有用,一共有三部分-Talked about in great detail and hope for all of us, a total of three parts
2022-02-25 14:04:31下载
积分:1