1
00:00:00,710 --> 00:00:01,960
Hello, welcome back.

2
00:00:02,270 --> 00:00:10,130
And this lesson we going to experiment with task priorities, so far we've been creating tasks with

3
00:00:10,130 --> 00:00:11,640
the same priority level.

4
00:00:12,260 --> 00:00:18,230
This time we agreed to experiment, changing the priorities and see what happens.

5
00:00:18,260 --> 00:00:22,280
I'm going to make a copy of our Task Creation Project Project's number one over here.

6
00:00:22,820 --> 00:00:24,920
I'll call this number for.

7
00:00:27,770 --> 00:00:29,030
TASC Priority's.

8
00:00:35,620 --> 00:00:38,140
Or top priority, singular is better.

9
00:00:40,370 --> 00:00:42,080
OK, I'm going to open this.

10
00:00:44,480 --> 00:00:52,460
So in this project, we had three tasks blue, red and green, and each of them had a profiler and they

11
00:00:52,460 --> 00:00:55,610
had the same priority just to refresh your memory.

12
00:00:55,670 --> 00:00:57,910
Let's see what happens when we run this.

13
00:00:58,280 --> 00:01:01,430
Remember, in each task function, we have the profiler.

14
00:01:01,430 --> 00:01:03,050
We increment in these variables.

15
00:01:03,260 --> 00:01:08,540
So we're going to observe them in the live expressions window to see the behavior, whether they are

16
00:01:08,540 --> 00:01:11,510
similar or click over here to build.

17
00:01:14,130 --> 00:01:14,910
Go to Dybbuk.

18
00:01:16,030 --> 00:01:17,740
A select number four here.

19
00:01:18,820 --> 00:01:19,810
And then OK.

20
00:01:24,090 --> 00:01:25,020
And then I'll switch.

21
00:01:26,490 --> 00:01:30,720
OK, I'll go to live expressions over here and then.

22
00:01:32,050 --> 00:01:34,780
A, you see, they have almost the same values.

23
00:01:35,880 --> 00:01:41,100
OK, we can post this, the values are almost the same, almost the same.

24
00:01:42,640 --> 00:01:49,510
Right is because they have the same priority, meaning each of them is executing the same amount of

25
00:01:49,510 --> 00:01:57,910
time, 10 milliseconds or one milliseconds based on our take rate or based on our time quanta systems,

26
00:01:57,910 --> 00:02:01,570
which we shall take a look at when we start looking at the last sentence.

27
00:02:02,780 --> 00:02:10,190
For example, if the CUENTA is set at 10 times, this means each task would execute for 10 times 10

28
00:02:10,190 --> 00:02:11,030
milliseconds.

29
00:02:11,300 --> 00:02:14,240
That's what that means after 10 a.m. is the scheduled.

30
00:02:15,680 --> 00:02:23,960
Schedules, the next task, the first task stops executing and the next one executed for 10 months as

31
00:02:23,960 --> 00:02:24,330
well.

32
00:02:24,350 --> 00:02:30,710
And then the next one, so they'll end up with the same amount of execution as we can see over here

33
00:02:31,400 --> 00:02:34,610
with our count of variables known as the task profiler.

34
00:02:35,850 --> 00:02:37,560
OK, so stop over here.

35
00:02:38,070 --> 00:02:39,690
What I'm going to do now is.

36
00:02:40,760 --> 00:02:46,880
I'm going to change the priority of task number of task green over here.

37
00:02:46,910 --> 00:02:52,080
I'm going to change the priority to to remember the smaller the number, the higher the priority.

38
00:02:52,430 --> 00:02:59,050
So changing this to priority to effectively makes this the lowest priority amongst the three.

39
00:02:59,870 --> 00:03:01,310
So click over here to run.

40
00:03:03,690 --> 00:03:06,360
And then click here, debug.

41
00:03:09,670 --> 00:03:10,480
And then switch.

42
00:03:13,300 --> 00:03:14,810
And then click here to run.

43
00:03:19,100 --> 00:03:20,280
That's right, strange.

44
00:03:20,870 --> 00:03:21,650
We have just.

45
00:03:22,700 --> 00:03:23,780
Green running.

46
00:03:24,780 --> 00:03:27,930
Oh, Green has priority of two.

47
00:03:28,860 --> 00:03:30,160
So let's see.

48
00:03:32,070 --> 00:03:38,970
OK, so, yeah, the reason Green is running is twofold.

49
00:03:39,510 --> 00:03:40,290
Oh, explain.

50
00:03:40,740 --> 00:03:45,990
So in free, the larger the number, the higher the priority.

51
00:03:45,990 --> 00:03:53,460
Unlike other time operating systems that I'm used to, I have courses on four different time operating

52
00:03:53,460 --> 00:03:53,970
systems.

53
00:03:53,970 --> 00:03:56,400
So you should bear with me when I make this confusion.

54
00:03:56,700 --> 00:04:01,190
So with free ARTUS, the larger the number, the higher the priority.

55
00:04:01,200 --> 00:04:01,680
So.

56
00:04:04,330 --> 00:04:11,320
Number two over here is essentially the largest priority number, the other tasks have task priority

57
00:04:11,320 --> 00:04:13,330
level one one, and this has level two.

58
00:04:13,780 --> 00:04:15,880
So as the highest priority number.

59
00:04:17,130 --> 00:04:17,560
Right.

60
00:04:18,150 --> 00:04:24,930
So what is happening here is that there are certain rules to the shetler, one of the rules is that

61
00:04:26,070 --> 00:04:30,390
a lower priority task cannot interrupt a higher priority task.

62
00:04:33,260 --> 00:04:42,650
What that means is as soon as your tasks stop having the same priority level they no longer operating

63
00:04:42,650 --> 00:04:48,920
in, in the timesharing mode that I explain, the time sharing mode is the mode where each of them is

64
00:04:48,920 --> 00:04:52,520
assigned a specific amount of time to execute.

65
00:04:52,880 --> 00:04:56,430
Once they are done executing, the next task is executed.

66
00:04:56,930 --> 00:05:00,120
This happens when all of them have the same priority.

67
00:05:00,350 --> 00:05:07,160
This is known as Round-Robin scheduling, but as soon as one has a priority greater than the rest,

68
00:05:07,310 --> 00:05:08,740
just I want to execute.

69
00:05:08,750 --> 00:05:09,320
Why?

70
00:05:09,590 --> 00:05:15,500
Because a lower priority task cannot overtake a higher priority task.

71
00:05:15,800 --> 00:05:20,570
And we should explain this further in theory when we look at the task states.

72
00:05:21,170 --> 00:05:21,620
Right.

73
00:05:21,650 --> 00:05:25,760
So the reason this is executing is that this is the highest priority task.

74
00:05:26,390 --> 00:05:28,340
These tasks have lower priority.

75
00:05:28,340 --> 00:05:33,890
So they cannot they cannot interrupt this task and execute.

76
00:05:33,920 --> 00:05:39,800
That is why this is the only one executed you would see over here or the others are not blue and red.

77
00:05:39,800 --> 00:05:41,330
They are just stuck in this one.

78
00:05:41,630 --> 00:05:44,960
Blue and red have a lower priority compared to green.

79
00:05:45,490 --> 00:05:50,960
OK, so we're going to increase the priority level of red and see what happens.

80
00:05:52,620 --> 00:05:56,970
We said right to two, I'm going to click over here, so now we have.

81
00:05:58,230 --> 00:06:05,550
Green and red with the same priority, blue has a lower priority, which is one click here to build.

82
00:06:06,880 --> 00:06:08,470
Click here to download onto the board.

83
00:06:12,180 --> 00:06:13,590
And then switch over here.

84
00:06:15,240 --> 00:06:22,290
And then I'll click here to run, and I can see now we have red and green running and blue, the lower

85
00:06:22,290 --> 00:06:28,530
priority cannot interrupt the higher priority, but if they have the same priority, they share that

86
00:06:28,530 --> 00:06:29,870
time amongst themselves.

87
00:06:30,120 --> 00:06:32,100
So now they are just passing the ball to each other.

88
00:06:32,100 --> 00:06:33,930
All the scheduling is the one doing this.

89
00:06:34,620 --> 00:06:40,410
The schedule is the one assigning the time to read and then to green to read and then to green because

90
00:06:40,410 --> 00:06:42,540
blue has a lower priority.

91
00:06:42,720 --> 00:06:44,780
OK, so let's see something.

92
00:06:45,300 --> 00:06:52,260
What if I increase their priority level of blue to number three such that blue is three, red is too

93
00:06:52,260 --> 00:06:53,070
green is too.

94
00:06:53,100 --> 00:06:54,140
Let's see what happens.

95
00:06:54,510 --> 00:06:55,560
I'll click here to build.

96
00:06:57,850 --> 00:06:59,890
And then a click here to get onto the board.

97
00:07:03,910 --> 00:07:05,230
And then click here to switch.

98
00:07:07,220 --> 00:07:13,670
And then click here to play, as you can see, Lou, is the only task running because it's got the highest

99
00:07:13,670 --> 00:07:20,240
priority and these ones don't have a priority equal to blue, so they cannot get any of the time.

100
00:07:20,660 --> 00:07:22,860
OK, so these are some basic stuff.

101
00:07:23,260 --> 00:07:24,740
Next, what are we going to do in?

102
00:07:24,740 --> 00:07:29,530
The next lesson is to see how to change the task priority in real time.

103
00:07:29,900 --> 00:07:35,100
Over here, the priority is assigned during the the creation of the task.

104
00:07:35,540 --> 00:07:43,970
What if, let's say read, execute and we want to drop the priority of red after we've computed something

105
00:07:43,970 --> 00:07:44,320
else.

106
00:07:44,930 --> 00:07:46,880
We'll see how to do that in real time.

107
00:07:47,450 --> 00:07:49,940
And by real time, I mean in runtime.

108
00:07:50,210 --> 00:07:52,730
That's why I should say, rather than real time.

109
00:07:52,840 --> 00:07:55,760
OK, so I'll see you in the next lesson for that.
