mirror of
https://github.com/Hizenberg469/Dining_philosopher.git
synced 2026-04-19 18:02:25 +03:00
Dining Philosopher Problem Implemented using pthread POSIX Library
This commit is contained in:
23
din_ph.h
Normal file
23
din_ph.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef __DIN_PH_H__
|
||||
#define __DIN_PH_H__
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct phil_ {
|
||||
|
||||
int phil_id;
|
||||
pthread_t thread_handle;
|
||||
int eat_count;
|
||||
} phil_t;
|
||||
|
||||
typedef struct spoon_ {
|
||||
|
||||
int spoon_id;
|
||||
bool is_used; /* bool to indicate if the spoon is being used or not */
|
||||
phil_t* phil; /* If used, then which philosopher is using it */
|
||||
pthread_mutex_t mutex; /* For Mutual Exclusion */
|
||||
pthread_cond_t cv; /* For thread Co-ordination competing for this Resource */
|
||||
} spoon_t;
|
||||
|
||||
#endif /* __DIN_PH_H__ */
|
||||
Reference in New Issue
Block a user