1
00:00:00,600 --> 00:00:01,750
Hello, welcome back.

2
00:00:01,790 --> 00:00:09,690
In this lesson, we going to see how to change the priority of a task during runtime using the Simms's

3
00:00:09,690 --> 00:00:16,230
artists to appraise, I've going ahead to make a copy of our last project, and I've given it the name

4
00:00:16,230 --> 00:00:18,150
thread priority over here.

5
00:00:18,300 --> 00:00:25,620
And we're going to run this simple experiment so we know how our current project works to refresh your

6
00:00:25,620 --> 00:00:26,020
memory.

7
00:00:26,040 --> 00:00:27,930
I'm simply going to run this.

8
00:00:28,820 --> 00:00:29,930
I'm going to build this.

9
00:00:32,550 --> 00:00:33,780
This is our new project.

10
00:00:34,870 --> 00:00:36,580
Right, and I'm going to run it.

11
00:00:39,430 --> 00:00:47,320
So I'll see debuggers ASTM 32, iSelect 36, and it's going to go to the DeBacker.

12
00:00:51,910 --> 00:00:52,630
It's open in.

13
00:00:56,640 --> 00:00:57,960
Now click here to switch.

14
00:01:01,690 --> 00:01:02,230
OK.

15
00:01:03,170 --> 00:01:09,830
So when I click this, I'll run and all of them are running the incrementing the same because they all

16
00:01:09,830 --> 00:01:11,120
have the same priority.

17
00:01:11,150 --> 00:01:12,740
OK, so what are we going to do?

18
00:01:12,740 --> 00:01:21,230
Is we going to let the orange task or thread change the priority of the.

19
00:01:22,420 --> 00:01:28,090
Of, let's say, the green thread to do this, we need to add something else to our threads.

20
00:01:28,510 --> 00:01:31,390
When we create our thread, our thread retains an idea.

21
00:01:31,420 --> 00:01:38,260
We need to store the idea of the thread somewhere so that we can use the idea of the thread to access

22
00:01:38,410 --> 00:01:40,920
or control the particular thread we are interested in.

23
00:01:41,290 --> 00:01:45,460
So I'm going to come up here and declare for variables of type.

24
00:01:45,460 --> 00:01:49,960
Always thread on the school, always thread.

25
00:01:50,410 --> 00:01:52,300
It is called actually Enniscorthy.

26
00:01:53,360 --> 00:01:57,170
That's the type, and we're going to have read it for our red thread.

27
00:01:57,380 --> 00:02:06,050
We're going to have green eyed creature of blue eyed green to have orange eyed.

28
00:02:07,860 --> 00:02:14,170
OK, so what are we going to do is whenever we create a threat, the ID is retained.

29
00:02:14,190 --> 00:02:18,730
We didn't make use of this ID in our first example, but now we're going to make use of it.

30
00:02:18,750 --> 00:02:25,110
I'm going to copy the Green ID and I'll come over here when we create the green thread is going to return.

31
00:02:25,110 --> 00:02:30,270
The ID will start here and I'm going to do the same for all of them.

32
00:02:30,660 --> 00:02:37,170
OK, this is for Red Threat is going to return the ID stories and read it over here.

33
00:02:38,160 --> 00:02:40,660
And I'm going to come down here.

34
00:02:40,710 --> 00:02:44,010
This one is for Orange Threat is going to return the ID.

35
00:02:44,010 --> 00:02:45,570
I'm going to store it over here.

36
00:02:48,400 --> 00:02:56,250
Range like this, and finally, Blue is going to return the ID and I'm going to store it in blue, ID

37
00:02:56,460 --> 00:02:57,120
like this.

38
00:02:59,220 --> 00:03:07,050
OK, so now that each threat has its ID stored, we going to use the thread ID to change the.

39
00:03:08,090 --> 00:03:14,840
Priority of the green threat, so I'm going to come to the orange threat when the orange threat executes,

40
00:03:15,380 --> 00:03:22,070
when it's executed was is going to set, let's say it's going to increase the priority of the green

41
00:03:22,070 --> 00:03:22,430
threat.

42
00:03:22,850 --> 00:03:28,250
So we come over here and the function we use, which we can find in our documentation.

43
00:03:28,250 --> 00:03:34,010
Remember the documentation I showed you how to open it for a reason or the functions can be found here.

44
00:03:34,250 --> 00:03:34,750
OK.

45
00:03:36,180 --> 00:03:48,240
Right, so we can come over here and we say always thread set priority, so this takes two arguments.

46
00:03:48,600 --> 00:03:53,640
The first argument is the idea of the thread, whose priority you want to set.

47
00:03:53,970 --> 00:03:56,130
We want to set the priority of green.

48
00:03:58,450 --> 00:04:04,510
Thread, so the next argument is the new priority you want to assign to it over here, we want to give

49
00:04:04,510 --> 00:04:06,460
it a priority above normal one.

50
00:04:06,790 --> 00:04:07,410
So I'll see.

51
00:04:07,430 --> 00:04:10,030
Always priority.

52
00:04:13,980 --> 00:04:22,980
Above normal one like this, and we saw the table where we had a list of priorities, OK, if you want

53
00:04:22,980 --> 00:04:24,540
to know more about the priorities.

54
00:04:26,090 --> 00:04:27,650
You can find them here.

55
00:04:29,920 --> 00:04:37,510
The states, the priorities, so there's always priority, non priority I do this is this priority is

56
00:04:37,510 --> 00:04:39,280
in descending order of magnitude.

57
00:04:40,060 --> 00:04:45,610
The the the higher the priority, the lower it is in the stable.

58
00:04:46,330 --> 00:04:47,740
OK, so that's priority.

59
00:04:47,740 --> 00:04:48,220
No more.

60
00:04:48,220 --> 00:04:48,610
No more.

61
00:04:48,610 --> 00:04:51,130
Plus one you say always priority number one.

62
00:04:51,670 --> 00:04:55,330
No more plus two is always priority normal two etc..

63
00:04:55,600 --> 00:04:58,180
OK, and then there is always priority.

64
00:04:58,180 --> 00:04:58,570
Hi.

65
00:04:58,870 --> 00:05:01,380
I wonder how come they decided to name it this way.

66
00:05:01,630 --> 00:05:07,870
In any case, we're going to give this always priority one because our threads here have always priority

67
00:05:07,900 --> 00:05:08,410
normal.

68
00:05:08,620 --> 00:05:15,340
So we know after the execution of this line, the highest priority thread becomes the green thread.

69
00:05:15,800 --> 00:05:18,190
Let's see if this works.

70
00:05:18,670 --> 00:05:19,840
I'm going to click here to build.

71
00:05:26,460 --> 00:05:28,470
I think there is an anomaly.

72
00:05:29,820 --> 00:05:30,400
Huh?

73
00:05:30,760 --> 00:05:34,280
OK, over here, I misspelled priority.

74
00:05:35,220 --> 00:05:36,300
Click here to build again.

75
00:05:39,310 --> 00:05:40,120
It's built in.

76
00:05:42,070 --> 00:05:45,370
To build successfully, going to click here to download onto the board.

77
00:05:49,160 --> 00:05:50,000
It's open in.

78
00:05:53,370 --> 00:05:54,170
Click to switch.

79
00:05:57,760 --> 00:05:58,360
And.

80
00:06:00,330 --> 00:06:02,520
It's ready, so I'm going to click here to run.

81
00:06:04,610 --> 00:06:05,710
Let's see what happens.

82
00:06:07,180 --> 00:06:13,390
OK, so now we have just the green thread running across, indeed, we were able to change its priority

83
00:06:13,390 --> 00:06:17,790
in runtime using the OS thread priority search function.

84
00:06:18,400 --> 00:06:24,980
So that's all there is if you wish to change the priority in runtime using CMS is outsourced to API.

85
00:06:25,270 --> 00:06:26,440
It's as simple as this.

86
00:06:26,930 --> 00:06:27,430
OK.
