So welcome back, guys.
Now, in this section of the course, we will get ourselves familiar with some technical words which
is related to Multi-threading world.
So this section will be a little bit theoretical.
We will going to understand the exact meaning of these words, that is context switching, concurrency
and parallelism.
Because when we will be doing assignments and projects on Multi-threading, then in order to explain
the Multithreading concepts, I would be using these terms too often.
So let us try to understand the meaning of these words in this section.
So to start with, let us understand what exactly concurrency means.
So concurrency simply means that doing two or more different tasks, but the pattern in which you are
doing these tasks determines whether it is a concurrency or not.
So if you do two or more tasks such that you do only one task at a time and you switch between the task.
Now there is a condition that is imposed while you switch between these tasks.
If you switch between the task by preempting the current task that you are doing, then picking up the
next task partially do it and then preempt it again.
Then again picking up the next task, partially do it and then preempt it again.
And you continue to follow the same pattern, right?
And eventually you will end up picking up the first task from the same point where it was left.
Then again, you partially do it and again you preempt it, right?
So you will continue to perform each task in a round robin fashion, preempting the one task, picking
up the next, and so on.
So if you perform two or more tasks in this fashion, then this shows the property of concurrency,
right?
Let us take one real world example which shows the property of concurrency.
So let us suppose that there are three well-diggers that is three persons which has the responsibility
to dig the well, and they are assigned a task to dig their respective 100ft deep.
Well.
Right.
So if there are three well diggers, then each of the well digger has to dig 100ft deep.
Well, right.
So it means that there are three wells to be digged and there is a condition that all three well diggers
have only one well drilling tool.
Right.
Which they have to share.
Right.
So now let us see that.
In what pattern should they dig the well so that the property of concurrency is honored.
So the conditions or constraints that need to be imposed on three well, Digger is that that only one
person can dig a well at a time.
And this is quite obvious because in this example there is only one drilling tool available, right?
So it is quite obvious that only one person can dig a well at a time.
And when current person who is digging the well take rest because he got tired, then the current person
hand over the digging tool to the second person and second person resumed digging his well from the
same point where he left last time.
Similarly, when second person got tired and he wants to take rest, he hand over the digging tool to
the third person and third person resumes again.
Right.
And this process continues until all the three well-diggers complete their respective tasks.
That is all the three well diggers successfully dig their respective 100ft deep.
Well, right.
So you can see that this real world example shows the property of concurrency.
We can conclude that work of all the three well diggers was in progression, right?
Though they were slow because they had to share the same well drilling tool between them.
But at least we can say that the work of all the three well diggers was in progression.
It was not like that.
That one.
Well, Digger had not even started and the rest two were digging the well one by one.
Right.
At any given point of time.
There was some percentage of work completed by each of the three Well-diggers Right.
So two or more tasks which is done in this fashion are concurrent in nature, right?
Later, we will try to map this real world example to the world of Multithreading and see that exact
same pattern is followed by multiple concurrent threads.