Hello, guys, and welcome and this lecture I'm going to show you, if two tasks are trying to write
to the three year monitor at the same time without a goat like semaphore, what kind of crashes are
going to happen?
What kind of that the corruption is going to happen?
So let us do that.
First, I'm going to include the library ordering of the authors that H as usual.
Next, I'm going to create my micro.
We have already created these two lines before.
This is why I'm trying to go faster through these steps.
Next, I'm going to be creating two tasks right now.
I'm going to go voit set up.
And I'm going to say next desk create.
And first one will be the first task, which is writing to Serial.
Now both that could be writing for your monitor, which is the results that they are both sharing and
trying to write to at the same time.
So the first one is going to be called desk arterials one.
Name is serial one.
And the stag is under 28 bites, then we have no priority is one.
Now we have no and that's it.
Now I'm going to create another task which will do exactly the same.
Job as the first task, but we're doing this in order to see the contradiction.
We're going to rename these ones tattoos.
OK, that's a this is all I need to hear, right?
So next, I need for a loop.
It will be empty.
I don't need to do anything in the void loop.
Lastly, I need the task itself.
So we have Voit task.
Old one goes to avoid pointer, and now we're going to run the task.
The task is very simple.
Say surreal, the print Allen and I'm going to print the following statement.
I am in task serial one game as simple as that.
Then I'm going to delay a little bit or delay.
Remember, DeLay here is going to be a multiple of 15 all the time, so the lowest you can go is 15
milliseconds.
So here I'm going to go with 30 milliseconds.
Now, I'm going to copy this.
I'm going to pasted it here, rename this task to and the print here I am in Task Serial two and that's
it.
Now we're going to see what kind of data corruption's going to happen.
Usually what we expect that first line will be printed.
OK, I mean, that's a real one that I am industrial to this.
Should the flip in between these two as simple as that.
Right.
Now, let me upload this, my Audrina is connected right now what we're doing, no.
I have some kind of error up there, all right, we forgot to initialize the cereal, so the cereal
begin.
OK, now let us upload.
Again, we have another error, we forgot to add the parentheses for void setup.
OK as well.
All right, let us applaud again.
I'm going to go to Syria monitor.
I'm going to reset my Audrey now and see what's going to happen.
Now we are printing serial one and serial two, and this is what we expect, right?
I mean, both of these functions will execute once.
This is not a loop.
No, so far I have no contradiction.
Every time I said I am presenting to you, one answer to that is totally normal.
I don't see any area.
However, let us put this in an infinite loop.
So this will be while one member, while one is an infinite loop.
So this function will repeat forever.
I'm going to include these instructions in one.
While I'm here as well.
Now, these two tasks will repeat forever.
OK, in the previous case, we were only executing them once.
Now they're repeating forever.
Let us go.
Let's go see your monitor.
Now, I'm going to stop the scroll down, take a look here.
So you'll do one, three, two, and then I have some weird things going on here, they are like merged
together and as you can see this merging, I am in task one.
I in tasks or you'll do as you can see, I have a lot of corrupted data because I'm trying to share
the same resource from both tasks at the same time, see the corruption that is happening.
This is not a healthy program.
So you want to be executed at once.
Sometimes we can avoid the corruption when both of these are not trying to access it exactly at the
same time.
But when I do, crazy stuff starts to happen.
All right.
So next lecture, we're going to resolve this.