⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p_c.c

📁 操作系统课程设计
💻 C
字号:
#include "P_C.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#pragma comment(lib, "P_C_Dll.lib")

int main(int argc, char ** argv)
{
	ContainerType c = C_LOOP_QUEUE;
	UINT producerTimer = 500;
	UINT consumerTimer = 1000;
	int opr, res;

	if(argc >= 2)
	{
		if(strlen(argv[1]) >= 4)
		{
			if(argv[1][0] == '/' && argv[1][1] == 'c' && argv[1][2] == ':')
			{
				if(argv[1][3] == 's')
					c = C_STACK;
				else if(argv[1][3] == 'q')
					c = C_LOOP_QUEUE;
			}
		}
	}

	Initialize(c, producerTimer, consumerTimer);

	ProducerStart();
	ConsumerStart();

	printf("                      生产者——消费者模拟系统\n");
	printf("----------------------------------------------------------------------\n");
	printf("   Producer                               Consumer\n");
	printf("----------------------------------------------------------------------\n");

	ResumeAll();

	while(1)
	{
		system("pause > nul");
		SuspendAll();
		printf("----------------------------------------------------------------------\n");
		printf("Select an operation(1, 2, 3):\n");
		printf("\t1. 更改生产者速度\n\t2. 更改消费者速度\n\t3. 退出程序\n");
		do{
			printf("\n>");
			res = scanf("%d", &opr);
			rewind(stdin);
		}while(res == 0 || (opr != 1 && opr != 2 && opr != 3));

		if(opr == 1)
		{
			printf("输入生产者时间间隔( >50 ):\n");
			do{
				printf("\n>");
				res = scanf("%d", &producerTimer);
				rewind(stdin);
			}while(res == 0 || producerTimer <= 50);

			printf("                      生产者——消费者模拟系统\n");
			printf("----------------------------------------------------------------------\n");
			printf("   Producer                               Consumer\n");
			printf("----------------------------------------------------------------------\n");
			ResumeAll();
			SetProducerTimer(producerTimer);
		}
		else if(opr == 2)
		{
			printf("输入消费者时间间隔( >50 ):\n");
			do{
				printf("\n>");
				res = scanf("%d", &consumerTimer);
				rewind(stdin);
			}while(res == 0 || consumerTimer <= 50);

			printf("                      生产者——消费者模拟系统\n");
			printf("----------------------------------------------------------------------\n");
			printf("   Producer                               Consumer\n");
			printf("----------------------------------------------------------------------\n");
			ResumeAll();
			SetConsumerTimer(consumerTimer);
		}
		else if(opr == 3)
		{
			/* ResumeAll(); */
			break;
		}
	}

	StopAll();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -