WEBVTT

00:05.040 --> 00:11.100
So guys, now let us discuss what are the data structures that we need to declare in order to solve

00:11.100 --> 00:12.780
our dining philosopher problem.

00:12.780 --> 00:17.940
So in the dining philosopher problem, you can see that there are usually two types of objects which

00:17.970 --> 00:19.440
interact with each other.

00:19.650 --> 00:23.000
The objects are the philosophers and the spoons.

00:23.010 --> 00:29.610
So it simply means that we need to define the data structures which represents philosophers and which

00:29.610 --> 00:31.800
represent spoons, right?

00:32.700 --> 00:39.810
So in the header file dining philosophers, we have declared or defined the data structures, philosophers

00:39.810 --> 00:41.240
and the data structure.

00:41.250 --> 00:42.060
Spoons.

00:42.060 --> 00:42.840
Right.

00:45.000 --> 00:50.340
Now let us discuss the fields of each of these data structures and what is the use of those fields one

00:50.340 --> 00:51.090
by one.

00:51.330 --> 00:56.190
So if you notice that the philosopher data structure has a philosopher ID.

00:56.580 --> 01:02.970
So in the diagram on the right hand side, you can see that I am addressing the philosophers as th zero

01:02.970 --> 01:05.790
PS1, PS2, PS3, etcetera.

01:05.790 --> 01:06.540
Right.

01:06.570 --> 01:12.690
So it simply means that each philosopher has been given a unique ID 0123 up to N.

01:13.020 --> 01:13.860
Right.

01:14.070 --> 01:18.360
So it is this philosopher ID which uniquely identifies the philosopher.

01:18.510 --> 01:22.440
And we also discussed that philosophers are nothing but they are threads.

01:22.470 --> 01:26.970
Therefore, philosopher data structure needs to have a thread handle right.

01:27.360 --> 01:33.450
And the third member usually do not contribute towards the solution of a dining philosopher problem.

01:33.570 --> 01:42.330
The eat count is a member which keeps a track regarding how many times a philosopher is able to grab

01:42.330 --> 01:46.290
an access to both the spoons and enjoy the cake.

01:46.300 --> 01:47.140
Right?

01:47.260 --> 01:53.920
So every time a philosopher is able to grab an access to both of his spoons, we will going to increment

01:53.920 --> 01:56.140
the eat count variable of that philosopher.

01:56.290 --> 02:00.250
So this is the data structure which represents the philosopher.

02:00.250 --> 02:03.310
And the second data structure is the spoon.

02:03.430 --> 02:06.220
And again, the spoon will have a spoon ID.

02:06.550 --> 02:13.030
So you can see on the diagram on the right hand side, spoons are given names such as SP zero, SP1,

02:13.120 --> 02:14.440
SP2, etcetera.

02:14.620 --> 02:18.220
So every spoon is given an ID, which is an spoon ID.

02:18.670 --> 02:24.250
Now the second variable of the spoon is a boolean variable, which is either true or false.

02:24.280 --> 02:32.080
So as the name suggests, if the spoon is being used by any philosopher, then that particular spoon

02:32.080 --> 02:38.440
is said to be being used and we will set is used flag for that spoon to true.

02:38.620 --> 02:39.430
Right.

02:39.430 --> 02:45.970
And since that spoon is being used by some philosopher, therefore the third member that is this philosopher

02:45.970 --> 02:52.120
pointer will be set to point to that philosopher which has got an access to the spoon.

02:52.360 --> 02:53.140
Right?

02:53.140 --> 02:59.170
So basically here we are keeping a track that if the spoon is being used, then which philosopher is

02:59.170 --> 03:00.430
using that spoon?

03:00.520 --> 03:01.390
Right?

03:01.390 --> 03:08.170
And if the philosopher released the spoon then is used, member of the spoon will be set to false.

03:08.170 --> 03:14.560
And since there is no philosopher who is using that spoon, therefore this philosopher pointer will

03:14.560 --> 03:15.850
be reset to null.

03:16.060 --> 03:16.900
Right.

03:17.470 --> 03:24.730
And in this dining philosopher problem, the spoon is a resource for which the philosophers are competing.

03:24.730 --> 03:25.480
Right?

03:25.510 --> 03:32.080
Therefore, therefore spoon as a resource will have its own mutex and a condition variable.

03:32.080 --> 03:32.860
Right?

03:33.190 --> 03:38.350
So both of these two data structures have been defined in the fine dining philosopher dot H.

03:38.440 --> 03:46.440
So if you take a look at the header file, you can see that I'm in the file dining philosopher dot h.

03:46.450 --> 03:49.960
And both these data structures have been defined already.

03:49.960 --> 03:56.350
Right now you understand what is the meaning of these two data structures and what each field of these

03:56.350 --> 03:58.240
data structure is used for.

03:58.480 --> 04:02.950
Now, in the next lecture video, we will going to set up our assignment program.
