#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 48
下载积分: 2 下载次数: 1

代码说明:

#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 只小白兔&

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

发表评论

0 个回复

  • 最新版本,1.16版本的ARM(的7TDMI,720T,920T)对uC/OS移植
    The latest release, ver 1.16 of the ARM (7TDMI, 720T, 920T) port for uC/OS-II V2.61 (and higher) includes ports for the following platforms: 1. S3c2410x ( ARM920T from Samsung ) on SMDK2410 eval board. 2. LPC2xxx - LPC210x & LPC213x ( ARM7TDMI-S from Philips ) on IAR s Kickstart & OLIMEX boards. 3. EP7312 ( ARM720T from CIRRUS ) on CDK238 eval board. Should also work on boards based on the CS89712. Tool-chains: GCC 3.3.2, ADS 1.2 & SDT 2.51. Op-modes: Pure ARM & ARM-THUMB interworked. Endianess: Big endian & Little endian modes-The latest release, ver 1.16 of the ARM (7TDMI, 720T, 920T) port for uC/OS-II V2.61 (and higher) includes ports for the following platforms: 1. S3c2410x ( ARM920T from Samsung ) on SMDK2410 eval board. 2. LPC2xxx- LPC210x & LPC213x ( ARM7TDMI-S from Philips ) on IAR s Kickstart & OLIMEX boards. 3. EP7312 ( ARM720T from CIRRUS ) on CDK238 eval board. Should also work on boards based on the CS89712. Tool-chains: GCC 3.3.2, ADS 1.2 & SDT 2.51.
    2023-09-06 15:45:03下载
    积分:1
  • 通过研究Linux的线程机制和信号量实现读者写者(Reader
    通过研究Linux的线程机制和信号量实现读者写者(Reader-Writer)问题并发控制。 1)写-写互斥:不能有两个写者同时进行写操作; 2)读-写互斥:不能同时有一个线程在读,而另一个线程在写; 3)读-读允许:可以有一个或多个读者在读; 4)读者优先的附加限制:如果读者申请进行读操作时已有另一个读者正在进行读操作,则该读者可直接开始读操作; 5)写者优先的附加限制:如果一个读者申请进行读操作时已有另一个写者在等待访问共享资源,则该读者必须等到没有写者处于等待状态后才能开始读操作。 -By studying the Linux thread mechanism and semaphores realize readers who write (Reader-Writer) the issue of concurrency control. 1) to write- write mutex: Can not write at the same time there are two write operations 2) read- write mutex: Can not have a thread at the same time in reading and writing another thread 3) Reading- Reading of permit: can have one or more readers read 4) the priority of additional restrictions readers: If the readers apply for a read operation, there was another reader being read, the reader can be directly started reading operation 5) to write additional priority Restrictions: If an application for a reader reading write operation has been in waiting for another visit to a shared resource, the read
    2022-02-06 09:26:49下载
    积分:1
  • a good banker's algorithm
    一个好好银行家算法-a good banker"s algorithm
    2022-03-22 09:10:35下载
    积分:1
  • 标签的例子
    Tab Example for iPhone
    2023-05-10 05:25:02下载
    积分:1
  • Operating system console procedures
    操作系统控制台程序-Operating system console procedures
    2022-12-10 01:15:03下载
    积分:1
  • uc/os源码的中文解析,很详细!值得一看呢
    uc/os源码的中文解析,很详细!值得一看呢-uc/os-source analysis of the Chinese, very detailed!
    2022-05-24 21:47:28下载
    积分:1
  • a simple core of the Minix operating system code, including all the underlying i...
    一个简单的操作系统minix的核心代码,包括所有的底层实现和上层架构。-a simple core of the Minix operating system code, including all the underlying implementation and the upper echelons.
    2022-01-28 14:34:09下载
    积分:1
  • Orange s:一个的实现(书附源码)chapter5.rar
    Orange s:一个操作系统的实现(书附源码)chapter5.rar-Orange" s: an operating system implementation (source code attached to the book) chapter5.rar
    2022-03-14 21:22:49下载
    积分:1
  • VC++ to achieve the relationship between producers and consumers! (OS)
    VC++实现生产者与消费者关系!(操作系统OS)-VC++ to achieve the relationship between producers and consumers! (OS)
    2022-03-03 04:39:04下载
    积分:1
  • Stanford iPhone课程配套源码,介绍people picker的用法。
    Stanford iPhone课程配套源码,介绍people picker的用法。-source code of Stanford iPhone course, demo of how to use People picker
    2022-03-21 05:03:07下载
    积分:1
  • 696518资源总数
  • 104313会员总数
  • 30今日下载