////////////////////////////////////////
//File : PhilosopherDining.c
//Author : Savage
//About : philosopher dining problem
//Savage (C) 2007
//EM:
[email protected]////////////////////////////////////////
////////////////HEAD FILES//////////////
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <time.h>
#include <sys/sem.h>
#include <sys/types.h>
#include <sys/shm.h>
#include <unistd.h>
#include <curses.h>
///////////////MACRO DEFINITION//////////////
#define N 5//the number of philosaphers
#define K 3+1//philosopher's state Kinds:3 + block time title num
#define THINKING 0//philosopher's thinking state
#define HUNGRY 1//philosopher's hungry state
#define EATING 2//philosopher's eating state
#define F ' '//representation of philosopher's state on screen
#define T -10//representation of philosopher's state on screen
///////GLOBE VARIABLE DECLARE AREA///////
double RunTime;//process execute_time
int state[N];//record philosophers's state
char scrstate[K-1][N];//record flag for screen
char LTitle[K][10]={"Thinking :"," Hungry :"," Eating :","WaitTime :"};//left title
int semid;//semaphore id
time_t start;//record rocking time
bool printbln[N];//boolean variable for contrl print block clocks
time_t blkclk[N];//record block time
//////////FUNCTIONS DECLARE AREA//////////
void P(int);//mutex semaphore P operate:semaphore - 1
void V(int);//mutex semaphore V operate:semaphore + 1
void initialize();//initialize semaphore ,philosophers' state,and so on
void OpenThread();//open thread for each philosopher
void philosopher(int);//philosopher's behavior
void iniscr();//initialize and start text graph mode
void exitscr();//exit text graph mode
void test(int);//To test the philosopher's state who is beside him
void ShowState();//Print the philosopher's state
void Printblkclk();//print philosapher blocked time
///////////////////MAIN PROCCESS/////////////////
main()
{
printf("*******Initializing...*******\n");