Hello and welcome!
In this video session we will see the overview of a thread.
In the previous videos, we have seen that Linux contains different processes and each process contains
a virtual memory of its own, and the user space of the process is divided into the code segment, the
data segment, the heap segment, and the stack segment.
Also, the memory of the process is private to itself.
This means the process cannot access the memory of other processes and the process runs concurrently.
Now a process can also create different threads within the process.
This means each thread that is created within the process can also run concurrently.
This gives an multi-threaded environment in which each of the threads that are created is scheduled
according accordingly by the scheduler.
The advantage of having a threads or the threads share the common virtual memory within the process,
and the different threads that are created within the process can share the different memory segments,
such as the code segment, the data segment, and the heap segment, and also each threads are given
their own set of stack.
So in this case, let's say the process has created two threads, and we have a stack segment for thread
one and the stack segment for thread two.
And the process itself is considered as a main thread.
And the process also has a stack segment.
So.
So in this case, all the three different threads can share data by reading or writing through the data
segment or the heap segment.
Thus communicating between the different threads is made using is made easy.
Also the different threads run concurrently.
This means each thread is given a specific CPU time and once the time slot is finished, the scheduler
can schedule the different threads and thus the different threads execute in a concurrent fashion.
One of the main advantage of having different threads within the processes, a given task can be subdivided
into smaller tasks, and and each of the thread can be assigned to perform the sub task, and collectively
all the threads perform the subtask and the bigger task can be accomplished.
So this is the advantage of having a thread.
In the next video sessions, we will see the detailed programming of the thread and how we deal with
the thread concepts in Linux systems.