So guys, now let us discuss what are the data structures that we need to declare in order to solve
our dining philosopher problem.
So in the dining philosopher problem, you can see that there are usually two types of objects which
interact with each other.
The objects are the philosophers and the spoons.
So it simply means that we need to define the data structures which represents philosophers and which
represent spoons, right?
So in the header file dining philosophers, we have declared or defined the data structures, philosophers
and the data structure.
Spoons.
Right.
Now let us discuss the fields of each of these data structures and what is the use of those fields one
by one.
So if you notice that the philosopher data structure has a philosopher ID.
So in the diagram on the right hand side, you can see that I am addressing the philosophers as th zero
PS1, PS2, PS3, etcetera.
Right.
So it simply means that each philosopher has been given a unique ID 0123 up to N.
Right.
So it is this philosopher ID which uniquely identifies the philosopher.
And we also discussed that philosophers are nothing but they are threads.
Therefore, philosopher data structure needs to have a thread handle right.
And the third member usually do not contribute towards the solution of a dining philosopher problem.
The eat count is a member which keeps a track regarding how many times a philosopher is able to grab
an access to both the spoons and enjoy the cake.
Right?
So every time a philosopher is able to grab an access to both of his spoons, we will going to increment
the eat count variable of that philosopher.
So this is the data structure which represents the philosopher.
And the second data structure is the spoon.
And again, the spoon will have a spoon ID.
So you can see on the diagram on the right hand side, spoons are given names such as SP zero, SP1,
SP2, etcetera.
So every spoon is given an ID, which is an spoon ID.
Now the second variable of the spoon is a boolean variable, which is either true or false.
So as the name suggests, if the spoon is being used by any philosopher, then that particular spoon
is said to be being used and we will set is used flag for that spoon to true.
Right.
And since that spoon is being used by some philosopher, therefore the third member that is this philosopher
pointer will be set to point to that philosopher which has got an access to the spoon.
Right?
So basically here we are keeping a track that if the spoon is being used, then which philosopher is
using that spoon?
Right?
And if the philosopher released the spoon then is used, member of the spoon will be set to false.
And since there is no philosopher who is using that spoon, therefore this philosopher pointer will
be reset to null.
Right.
And in this dining philosopher problem, the spoon is a resource for which the philosophers are competing.
Right?
Therefore, therefore spoon as a resource will have its own mutex and a condition variable.
Right?
So both of these two data structures have been defined in the fine dining philosopher dot H.
So if you take a look at the header file, you can see that I'm in the file dining philosopher dot h.
And both these data structures have been defined already.
Right now you understand what is the meaning of these two data structures and what each field of these
data structure is used for.
Now, in the next lecture video, we will going to set up our assignment program.