本文整理汇总了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;
}