?? simulation.h
字號:
//
// FILE: Simulation.h
//
// Copyright (c) 1997 by Aaron Michael Cohen and Mike Woodring
//
/////////////////////////////////////////////////////////////////////////
#include "Mcl4Mfc.h"
#define NUMBER_PHILOSOPHERS 5
#define MINIMUM_THINKING_TIME 250
#define MINIMUM_EATING_TIME 250
#define MAXIMUM_THINKING_TIME 5000
#define MAXIMUM_EATING_TIME 5000
#define WM_DININGSIM_PHILOSOPHER_UPDATE (WM_USER + 1024)
#define WM_DININGSIM_FORK_UPDATE (WM_USER + 1025)
#define PHILOSOPHER_STATE_HUNGRY 0
#define PHILOSOPHER_STATE_THINKING 1
#define PHILOSOPHER_STATE_EATING 2
#define FORK_STATE_AVAILABLE 0
#define FORK_STATE_UNAVAILABLE 1
// CTable object definition...
class CTable {
private:
// one mutex per fork...
CMclMutex m_cmForks[NUMBER_PHILOSOPHERS];
// table state...
BOOL m_bContinue;
// GUI window...
HWND m_hwndGUI;
public:
// constructor...
CTable();
// set the window which NotifyParent will send messages to...
void SetHwnd(HWND hwnd);
// take the forks needed by philosopher number nId...
void TakeForks(int nId);
// drop the forks taken by philosopher number nId...
void DropForks(int nId);
// philosophers call this to check if they
// should continue...
BOOL Continue(void);
// put table in stop state...
void Stop(void);
// table is ready to run...
void Run(void);
// send messages to the m_hwndGUI window...
void NotifyParent( UINT uMsg, WPARAM wParam, LPARAM lParam);
};
// CPhilosopher object definition...
class CPhilosopher : public CMclThreadHandler {
private:
// this philsophers position at the table...
int m_nId;
// pointer to the table that all philosopher share...
CTable *m_pTable;
public:
// constructor...
CPhilosopher( int nId, CTable *pt);
// thread handler entry point...
unsigned ThreadHandlerProc(void);
// philosopher activities...
void Philosophize(void);
void Think(void);
void Eat(void);
};
// CPhilosopherThread object definition...
class CPhilosopherThread : public CMcl4MfcWorkerThread {
private:
// pointer to the internal thread handler object...
CPhilosopher *m_pPhilosopher;
private:
// private constructor for use by pseudo-virtual constructor...
CPhilosopherThread( CPhilosopher *pPhilosopher);
public:
virtual ~CPhilosopherThread();
// pseudo-virtual constructor to create philosophers...
static CPhilosopherThread *CreatePhilosopher( int nId, CTable *pt);
};
// CSimulation object definition...
class CSimulation {
private:
// simulation-wide table object...
CTable m_table;
// philosopher thread objects...
CMcl4MfcThreadAutoPtr m_cPhilosophers[NUMBER_PHILOSOPHERS];
public:
// set the window which will receive simulation update messages...
void SetHwnd(HWND hwnd);
// start the simulation...
void Run(void);
// stop the simulation...
void Stop(void);
};
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -