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


C++ Table::Run方法代码示例

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


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

示例1: main

/*
 * I'll first note that I've worked with an alternative version of the "Dining Philosophers" problem
 * where instead of spaghetti and forks, rice and chopsticks are used. It just seems to make more sense
 * in an admittedly strange situation where clean eating utensils are rare.
 *
 * My solution works with a Table class that holds information about the
 * philosophers seated around it and the chopsticks placed on it.
 *
 * The Philosophers are made aware of the the chopsticks, which are implemented as mutexes, on either side of them.
 * While the philosophers go through their cycle of eating and thinking they use the lock function
 * from the <mutex> library to lock two mutexes (the chopsticks) at once or wait until both are available,
 * this eliminates the risk of deadlock.
 *
 * And using the "eating = philosophers/2" algorithm to asses how it performs
 * it seems to achieve this number consistently.
 */
int main(int argc, char* argv[]) {

	//A table pointer
	Table *table;

	//Crate a Table object depending on arguments
	if(argc == 1){
		table = new Table(6, 5, "philo.log");
	}
	else if(argc == 2){
		table = new Table(atoi(argv[1]), 5, "philo.log");
	}
	else if(argc == 3){
		table = new Table(atoi(argv[1]), atoi(argv[2]), "philo.log");
	}
	else if(argc == 4){
		table =  new Table(atoi(argv[1]), atoi(argv[2]), argv[3]);
	}

	//Run table
	table->Run();

	//Delete table
	delete table;

	//Return 0
	return 0;
}
开发者ID:Sasamus,项目名称:dining-philosophers,代码行数:44,代码来源:main.cpp


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