So guys, now let us make ourselves familiar with the very fundamental problem to multithreading and
thread synchronization, and that is the spurious wakeups.
So when you design multithreading solutions or when you write Multithreading code, you need to take
care that you do not cause spurious wakeup problem.
So we will first discuss what spurious wakeup are and how it can be handled or it can be resolved.
It is the programmers responsibility to avoid spurious wakeup.
As such, there is no API or no system call which can avoid spurious wakeup.
It's a logical problem which a developer of a multithreading applications must handle.
So a spurious wakeup is all about that.
You wake up only to find whatever you were promised or told has been broken or is a lie.
Right?
So probably this statement make less sense to you as of now.
So let us discuss with the help of our example.
So let us suppose that you receive a phone call from your friend and he invites you for a booze party
at a common friend's house.
Right?
So common friend is a third friend where you guys are planning to get together while you are on the
way.
The common friend leaves the town out of some emergency and he did not even inform you.
So what will happen that you will eventually reach his home only to find that the common friend is nowhere?
Right.
So this is a situation of spurious wakeup to you.
You eventually find the truth.
And the truth is no less surprise to you.
It takes finite amount of time for you to reach your friend's house, and within that time interval,
the situation changed such that it was futile for you to reach your friend's house eventually.
Right?
Let us take one more example which demonstrates the spurious wakeup.
Your father.
Let us suppose bought sweets, which is exclusive for you, and he advised you to consume those sweets
after taking a bath.
So you go for a bath and your sibling is somewhat notorious guy.
He overheard this conversation between you and your father, and he eat all the sweets in the box,
leaving the box empty.
Right?
Now you come out of the washroom after taking a bath and you open the sweet box only to find that the
sweet box is empty.
Right.
So note the word.
It is something against your expectation in the previous example.
Also you reach your friend's house only to find that the friend was not at his house.
So it was also something that was against your expectation.
So in the second example also when you find the sweet box empty, then it was the spurious wakeup for
you.
So as a result, you are sad and angry.
So when you wake up spuriously you find that the situation is against your expectations.
In both of these examples, you ended up with a situation which was against your expectations, right?
You think you have been given wrong information by your friend in the first example or by your father
in the second example, but actually they did not give you wrong information.
It just happened that somebody else cheated you.
Right.
In both of these examples, in the first example, the common friend cheated you knowingly or unknowingly,
but your friend gave you the right information.
Right?
Similarly, in the second example, your father never cheated you.
He gave you the right information to have a sweets in the sweet box.
But it so happened that you eventually find the sweet box empty.
And you think that your father lied to you, right?
So now let us see that.
How this spurious wakeup is relevant in the world of Multithreading.
So when it comes to multithreading, when a thread gets unblocked, that is the thread which was blocked
on the wait system call.
So when the thread gets unblocked because it has received a signal, it can resume its execution due
to a reason which is no more valid.
Right.
So in the next lecture video we will going to understand this point with the help of an example, the
thread blocks because some condition was not fulfilled.
But when a thread receives a signal and starts its execution, that condition, because of which it
was blocked, is still not fulfilled.
That is called spurious wakeup for a thread.
So now let us see in the next lecture video how threads can be subjected to spurious wakeups and what
shall be the problem that would happen if the threads are subjected to spurious wakeups?
And as a developer or programmer, what you should do in order to prevent spurious wakeups of blocked
threads.