首先提供一些上下文,这是针对涉及信号量的赋值。我们要找到哲学家就餐问题的代码,让它发挥作用,然后进行一些分析和操作。但是,我遇到了一个错误。
原始代码取自http://www.math-cs.gordon.edu/courses/cs322/projects/p2/dp/ ,使用C++解决方案。
我在 Code::Blocks 中收到的错误是
philosopher.cpp|206|error: 'Philosopher_run' was not declared in this scope|
Run Code Online (Sandbox Code Playgroud)
并且此错误发生在该行中:
if ( pthread_create( &_id, NULL, (void *(*)(void *)) &Philosopher_run,
this ) != 0 )
Run Code Online (Sandbox Code Playgroud)
我查找了 pthread_create 方法,但无法修复此错误。如果有人可以向我解释如何纠正这个错误,以及为什么会发生这个错误,我将不胜感激。我试图仅提供相关代码。
class Philosopher
{
private:
pthread_t _id;
int _number;
int _timeToLive;
public:
Philosopher( void ) { _number = -1; _timeToLive = 0; };
Philosopher( int n, int t ) { _number = n; _timeToLive = t; };
~Philosopher( void ) {};
void getChopsticks( void );
void releaseChopsticks( void …Run Code Online (Sandbox Code Playgroud)