当前位置: 首页>>代码示例>>C++>>正文


C++ Sim::getcTime方法代码示例

本文整理汇总了C++中Sim::getcTime方法的典型用法代码示例。如果您正苦于以下问题:C++ Sim::getcTime方法的具体用法?C++ Sim::getcTime怎么用?C++ Sim::getcTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sim的用法示例。


在下文中一共展示了Sim::getcTime方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: compareCPU

bool compareCPU(Sim a, Sim b)
{
	return a.getcTime() < b.getcTime();
}
开发者ID:mengjunglin,项目名称:OpSys-Project--1,代码行数:4,代码来源:main2.cpp

示例2: sjf

/* Shortest-Job First (SFS)
 * This will sort the processes that are sent in based on the 
 * shortest job in the array. */ 
void sjf(Sim* p, int size)
{
	int tempWait = 0, minTurn = p[0].getTurnTime(), maxTurn = 0, 
		turnT = 0, minInitial = p[0].getITime(), maxInitial = 0, 
		initialT = 0, minWait = p[0].getWaitTime(), maxWait = 0, 
		totalW = 0;  

	elapsedTime = 0; 
	vector <Sim> arrived;

	int check = 1; 

	//push it into vector if it arrives at time 0
	for(int i = 0; i < size; i++)
	{
		if (p[i].getATime() == 0)
		{
			arrived.push_back(p[i]);
			check = i + 1;
		}
	}

	sort(arrived.begin(), arrived.end(), compareCPU); 

	cout << "\n\n\nShortest Job First without Preemption | Send Processes to CPU and run: \n"; 
	
	//for(int j = 0; j < size; j++) 
	int counter = 0;
	bool firstTime = true; 
	Sim temp; 
	while(counter != size)
	{ 
		for(int i = check; i < size; i++)
		{
			int totalTime = arrived[0].getcTime() + elapsedTime;
			if (totalTime > p[i].getATime())
			{
				arrived.push_back(p[i]);
				check = i + 1;
			}
		}
		temp = arrived[0];
		arrived.erase(arrived.begin()); // this process will have terminated so it can be removed from the vector
		sort(arrived.begin(), arrived.end(), compareCPU); // sorts all the processes that will be in the vector after the one terminates

		temp.setWaitTime(elapsedTime);
		printFirst(elapsedTime, temp.getpId(), temp.getWaitTime());	
		elapsedTime+=temp.getcTime(); 
		temp.setTurnTime(elapsedTime);
		printTerminate(elapsedTime, temp.getpId(), temp.getTurnTime(), temp.getWaitTime()); 
		firstTime = false;
		counter ++; 

		if (!firstTime && !arrived.empty( ))
		{
			elapsedTime = totalElapsedTime(elapsedTime); 
			printContextSwitch(elapsedTime, temp.getpId(), arrived[0].getpId());			
			elapsedTime = totalElapsedTime(elapsedTime);  
		} 
		
	} 

	dataToCollect(p, size, minTurn, maxTurn, turnT, minInitial, maxInitial, initialT, minWait, maxWait, totalW);
}
开发者ID:mengjunglin,项目名称:OpSys-Project--1,代码行数:67,代码来源:main2.cpp


注:本文中的Sim::getcTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。