So, guys, now let us quickly discuss one more example where you would need to design a process with
multiple threads.
So in the scenarios where work can be split up into smaller independent chunks, which can then be processed
by worker threads, if the total amount of work that a typical process needs to do could be divided
into smaller independent chunks, then it is best to design a process as a multi threaded process.
So let us take an example.
A multi threaded TCP server serving 100 TCP connected clients at the same time.
This is the example where it is best to design a TCP server as a multi threaded TCP server.
Right?
So for example, let us have a TCP server which is running on some machine, right?
And now let us suppose that there is some client C one which is present elsewhere in the network.
The client.
C1 could be running on any machine in the network which is reachable from this TCP server.
Now let us suppose that this client C1 established the TCP connection with the server, right?
And once the connection is established, the now TCP server and the client can exchange data with each
other.
Right?
So in this case, what can TCP server do is that that it can launch a new thread t one and it is the
thread t one which will talk with the client.
C one on behalf of TCP server.
Right.
Once the thread t one gets busy servicing the client c one the TCP server can do its some other important
work, right?
Similarly, there could be other clients in the network which can establish TCP connection with the
TCP server and participate in data exchange with the TCP server.
The TCP server for each of its connected client.
That is C one, C two and C three can launch a worker thread, T1, T2 and T3, which would talk to
their respective clients on behalf of Dhcp server.
Right.
The communication between the TCP server and the client is completely isolated with the communication
that is going on between the TCP server and other clients.
Right?
So TCP server are usually designed as multi-threaded or multi-process Dhcp servers.
Right.
So in this example, the TCP server delegates the task or work to worker threads to entertain the client
request.
Right.
So this is a specific term which is to be used in the multithreading environment and this term is called
delegation of work.
In this example, the TCP server delegates its work to its worker threads.
And what is the work?
The work is nothing, but it is servicing the clients.
So analogy is very simple.
It is just like a jewelry shop owner, which is the owner of the shop and is a rich man and such a rich
man, After understanding the client needs simply hand over the client to one of its subordinates to
carry out further transactions.
Right.
The main task of establishing the TCP connection is done between TCP server and the client.
But once the connection is established, then the rest of the data exchange between the TCP server and
the client takes place between the client and this worker thread, which is talking with the client
on behalf of TCP server.
Right.