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

📄 苹果桔子(vc).txt

📁 操作系统知识
💻 TXT
字号:
*************************************************************
*************************************************************
		//空盘子同步信号量
		CSemaphore Sem_Empty_Plate(1,1,"Sem_Empty_Plate",NULL);
		//苹果同步信号量
		CSemaphore Sem_Apple(0,1,"Sem_Apple",NULL);
		//桔子同步信号量
		CSemaphore Sem_Orange(0,1,"Sem_Orange",NULL);
		//保持环境存在
	        cin.get();
*************************************************************
*************************************************************
		//空盘子同步信号量
		CSemaphore Sem_Empty_Plate(1,1,"Sem_Empty_Plate",NULL);
		//苹果同步信号量
		CSemaphore Sem_Apple(0,1,"Sem_Apple",NULL);

        int i;
		for (i=0;i<20;i++)
		{
		cout<<"正在削苹果"<<endl;
	    cin.get();
        
		cout<<"想放苹果,准备发出请求"<<endl;
		cin.get();

		Sem_Empty_Plate.Lock();
		cout<<"可以放苹果"<<endl;
		cout<<"正在放苹果到盘子中"<<endl;
        cout<<"苹果已放到盘子中,准备通告"<<endl;
		cin.get();
		Sem_Apple.Unlock();
		
		cout<<"通告完毕,准备削苹果果"<<endl;
		cin.get();
		}
		 
*************************************************************
*************************************************************
		//空盘子同步信号量
		CSemaphore Sem_Empty_Plate(1,1,"Sem_Empty_Plate",NULL);
		//桔子同步信号量
		CSemaphore Sem_Orange(0,1,"Sem_Orange",NULL);

        int i;
		for (i=0;i<20;i++)
		{
		cout<<"正在剥桔子"<<endl;
	    cin.get();

		cout<<"想放桔子,准备发出请求"<<endl;
		cin.get();
        
		Sem_Empty_Plate.Lock();
		cout<<"可以放桔子"<<endl;
		cout<<"正在放桔子到盘子中"<<endl;
        cout<<"桔子已放到盘子中,准备通告"<<endl;
		cin.get();
		Sem_Orange.Unlock();

		cout<<"通告完毕,准备剥桔子"<<endl;
		cin.get();
		}

*************************************************************
*************************************************************
		//空盘子同步信号量
		CSemaphore Sem_Empty_Plate(1,1,"Sem_Empty_Plate",NULL);
		//苹果同步信号量
		CSemaphore Sem_Apple(0,1,"Sem_Apple",NULL);
        int i;

		for (i=0;i<20;i++)
		{
		cout<<"想拿苹果,准备发出请求"<<endl;
		cin.get();
        
		Sem_Apple.Lock();
		cout<<"可以拿苹果"<<endl;
		cout<<"正在从盘子中拿苹果"<<endl;
        cout<<"已从到盘子中拿到苹果,准备通告"<<endl;
		cin.get();
		Sem_Empty_Plate.Unlock();

        cout<<"通告完毕,准备吃苹果"<<endl;
      	cin.get();
    	cout<<"正在吃苹果"<<endl;
    	cin.get();
		}

*************************************************************
*************************************************************

⌨️ 快捷键说明

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