1
00:00:01,090 --> 00:00:02,560
Hello, welcome back.

2
00:00:02,590 --> 00:00:08,830
In this lesson, we going to see how to work with counting semaphores, I'm going to make a copy of

3
00:00:08,830 --> 00:00:12,100
our Lost Project, this number twenty here.

4
00:00:12,100 --> 00:00:17,770
I'm going to make a copy of, say, copy and then paste over here.

5
00:00:18,520 --> 00:00:20,680
And then I'll call this counting semaphores.

6
00:00:35,850 --> 00:00:38,430
When it's done, I'm going to close this old farmhouse.

7
00:00:39,620 --> 00:00:45,880
OK, so this is just a tiny bit of difference open, I may not see fall over here.

8
00:00:48,390 --> 00:00:55,590
And over here, where we created a SEMAFO, remember the projects, we made a copy of this for the SEMAFO

9
00:00:55,590 --> 00:00:57,560
Mutex, that's why we see this here.

10
00:00:57,840 --> 00:01:05,430
So if we want to create account in SEMAFO, the function to use is X semafo create counting and this

11
00:01:05,430 --> 00:01:07,080
function takes to document.

12
00:01:09,860 --> 00:01:12,200
The first argument is the total count.

13
00:01:13,580 --> 00:01:16,400
So we can say 10 and then the next argument.

14
00:01:17,310 --> 00:01:26,220
Is the initial count so you can think of this as using a bathroom or washroom analogy and the semaphores

15
00:01:26,220 --> 00:01:33,120
being the keys, so if we say we are creating account semaphore, we are saying accounting SEMAFO with

16
00:01:33,120 --> 00:01:35,820
a total count of 10, we are saying we have 10 keys.

17
00:01:36,940 --> 00:01:45,730
To, let's say, 10 separate bathrooms and initially zero of the keys is taken, so zero, so 10 is

18
00:01:45,730 --> 00:01:48,910
the total count, but in our case, our resources, a single one.

19
00:01:49,060 --> 00:01:54,080
In this experiment, we're using one zero port to print the data.

20
00:01:54,100 --> 00:02:00,720
So our number of count, total number of count is one and then initially zero.

21
00:02:00,970 --> 00:02:05,260
That is how we're going to initialize our account and SEMAFO and we leave everything the same.

22
00:02:05,380 --> 00:02:09,070
Let's build and see what we have or click here.

23
00:02:09,910 --> 00:02:10,630
Right, click.

24
00:02:11,790 --> 00:02:13,770
And built project over here.

25
00:02:15,410 --> 00:02:16,910
It's built successfully.

26
00:02:17,690 --> 00:02:18,320
Right click.

27
00:02:19,200 --> 00:02:24,570
And then I'll say run us ASTM 30 to a select number, twenty one over here.

28
00:02:25,480 --> 00:02:27,070
I say, OK, over here.

29
00:02:32,220 --> 00:02:36,630
Let's see, it's downloading, he says 97, it's done.

30
00:02:37,760 --> 00:02:40,700
OK, so this report, I'm going to open it.

31
00:02:43,440 --> 00:02:48,030
Cletis, I see real time, it's not responding.

32
00:02:49,100 --> 00:02:51,740
Going to close and open real tim.

33
00:02:54,380 --> 00:02:54,910
OK.

34
00:02:57,880 --> 00:03:00,100
OK, so the reason.

35
00:03:01,140 --> 00:03:08,490
It's not moving as this count in SEMAFO is just like the binary SEMAFO, before we use the SEMAFO,

36
00:03:08,490 --> 00:03:09,800
we first have to give it.

37
00:03:10,020 --> 00:03:13,280
We have to give the SEMAFO before the first function takes it.

38
00:03:13,740 --> 00:03:17,370
We realized that in our mutex example, we didn't have to give the SEMAFO.

39
00:03:17,370 --> 00:03:18,620
We could simply take it.

40
00:03:19,260 --> 00:03:24,540
But this time we have a single count and we have to give this.

41
00:03:27,070 --> 00:03:31,480
So before we start our scheduler, I will say eczema for give over here.

42
00:03:38,920 --> 00:03:40,180
It's pure successfully.

43
00:03:40,450 --> 00:03:41,770
I'm going to click here to run.

44
00:03:51,370 --> 00:03:54,460
It's downloaded successfully, I'm going to open our support.

45
00:03:56,540 --> 00:03:58,190
See, selectees.

46
00:04:02,520 --> 00:04:08,590
OK, as you can see, it's running when I press the push button, it becomes your right.

47
00:04:08,980 --> 00:04:09,510
OK.

48
00:04:12,960 --> 00:04:19,020
So you may wonder what is the difference between the binary semaphore and in this one, of course,

49
00:04:19,020 --> 00:04:23,610
the binary SEMAFO, like we said, there's one or zero two values.

50
00:04:24,540 --> 00:04:30,480
One key task is the haystack you or it does not, whereas this one, we can create as many clues as

51
00:04:30,480 --> 00:04:30,980
we want.

52
00:04:31,410 --> 00:04:36,050
And one other thing over here, we said this is the total number of count and this is initial count.

53
00:04:36,330 --> 00:04:44,400
If we want to give the key, if we want to give the key without using our zemi forgive here, we can

54
00:04:44,400 --> 00:04:48,960
simply set initial count to one so that we give it to the first the first task.

55
00:04:48,990 --> 00:04:50,010
So we don't need this.

56
00:04:50,190 --> 00:04:57,750
If we comment ximo give and then we said initial count to one, then our task would automatically receive

57
00:04:57,750 --> 00:04:57,960
it.

58
00:04:58,230 --> 00:05:00,750
We don't have to explicitly give from here.

59
00:05:00,960 --> 00:05:03,720
Let's see if what I'm saying is the way it works.

60
00:05:03,720 --> 00:05:04,920
I'll click over here to build.

61
00:05:10,180 --> 00:05:10,810
It's Putin.

62
00:05:12,930 --> 00:05:13,550
OK.

63
00:05:15,360 --> 00:05:16,530
Now click here to run.

64
00:05:18,730 --> 00:05:19,330
I see.

65
00:05:23,590 --> 00:05:25,960
OK, system initialization.

66
00:05:27,000 --> 00:05:27,590
AC.

67
00:05:29,220 --> 00:05:30,240
Verification.

68
00:05:31,230 --> 00:05:33,090
OK, as you can see, it's raining.

69
00:05:33,970 --> 00:05:34,720
The same way.

70
00:05:35,790 --> 00:05:42,090
OK, when I press the push button, we can see we received our data and we're not using this this we've

71
00:05:42,090 --> 00:05:45,930
commented out, but we set initial count one meaning we've given it.

72
00:05:46,530 --> 00:05:49,480
OK, so that's all there is for counting semaphores.

73
00:05:49,500 --> 00:05:50,630
I'll see you in the next lesson.

74
00:05:50,640 --> 00:05:51,390
Have a nice day.
