WEBVTT

00:06.090 --> 00:12.390
So, guys, now let us quickly discuss one more example where you would need to design a process with

00:12.390 --> 00:13.690
multiple threads.

00:13.710 --> 00:21.930
So in the scenarios where work can be split up into smaller independent chunks, which can then be processed

00:21.930 --> 00:28.290
by worker threads, if the total amount of work that a typical process needs to do could be divided

00:28.290 --> 00:34.850
into smaller independent chunks, then it is best to design a process as a multi threaded process.

00:34.860 --> 00:36.690
So let us take an example.

00:36.840 --> 00:42.470
A multi threaded TCP server serving 100 TCP connected clients at the same time.

00:42.480 --> 00:48.510
This is the example where it is best to design a TCP server as a multi threaded TCP server.

00:48.510 --> 00:49.280
Right?

00:49.290 --> 00:54.180
So for example, let us have a TCP server which is running on some machine, right?

00:54.300 --> 00:59.730
And now let us suppose that there is some client C one which is present elsewhere in the network.

01:00.900 --> 01:01.620
The client.

01:01.620 --> 01:06.840
C1 could be running on any machine in the network which is reachable from this TCP server.

01:06.960 --> 01:12.650
Now let us suppose that this client C1 established the TCP connection with the server, right?

01:12.660 --> 01:19.290
And once the connection is established, the now TCP server and the client can exchange data with each

01:19.290 --> 01:19.800
other.

01:19.800 --> 01:20.490
Right?

01:21.580 --> 01:28.720
So in this case, what can TCP server do is that that it can launch a new thread t one and it is the

01:28.720 --> 01:31.300
thread t one which will talk with the client.

01:31.330 --> 01:33.720
C one on behalf of TCP server.

01:33.730 --> 01:34.480
Right.

01:34.690 --> 01:41.740
Once the thread t one gets busy servicing the client c one the TCP server can do its some other important

01:41.740 --> 01:43.150
work, right?

01:43.330 --> 01:49.270
Similarly, there could be other clients in the network which can establish TCP connection with the

01:49.270 --> 01:53.680
TCP server and participate in data exchange with the TCP server.

01:53.770 --> 01:56.770
The TCP server for each of its connected client.

01:56.770 --> 02:04.360
That is C one, C two and C three can launch a worker thread, T1, T2 and T3, which would talk to

02:04.360 --> 02:07.390
their respective clients on behalf of Dhcp server.

02:07.390 --> 02:08.140
Right.

02:08.500 --> 02:14.590
The communication between the TCP server and the client is completely isolated with the communication

02:14.590 --> 02:18.130
that is going on between the TCP server and other clients.

02:18.130 --> 02:18.820
Right?

02:18.820 --> 02:25.040
So TCP server are usually designed as multi-threaded or multi-process Dhcp servers.

02:25.040 --> 02:25.700
Right.

02:26.140 --> 02:33.430
So in this example, the TCP server delegates the task or work to worker threads to entertain the client

02:33.430 --> 02:34.190
request.

02:34.210 --> 02:34.920
Right.

02:34.930 --> 02:41.020
So this is a specific term which is to be used in the multithreading environment and this term is called

02:41.020 --> 02:42.550
delegation of work.

02:42.910 --> 02:48.100
In this example, the TCP server delegates its work to its worker threads.

02:48.100 --> 02:49.150
And what is the work?

02:49.180 --> 02:52.630
The work is nothing, but it is servicing the clients.

02:54.800 --> 02:56.660
So analogy is very simple.

02:56.660 --> 03:03.350
It is just like a jewelry shop owner, which is the owner of the shop and is a rich man and such a rich

03:03.380 --> 03:09.350
man, After understanding the client needs simply hand over the client to one of its subordinates to

03:09.380 --> 03:11.360
carry out further transactions.

03:11.360 --> 03:12.140
Right.

03:12.350 --> 03:17.810
The main task of establishing the TCP connection is done between TCP server and the client.

03:17.810 --> 03:23.870
But once the connection is established, then the rest of the data exchange between the TCP server and

03:23.870 --> 03:30.260
the client takes place between the client and this worker thread, which is talking with the client

03:30.260 --> 03:32.000
on behalf of TCP server.

03:32.000 --> 03:32.690
Right.
