WEBVTT

00:05.860 --> 00:07.930
So, guys, welcome back.

00:07.930 --> 00:12.400
Now, in this section of the course, we will going to attack on Inter-thread communication.

00:12.400 --> 00:16.990
That is how to set up the communication between the threads of the same process.

00:17.470 --> 00:22.630
So we often feel the need to set up communication between independent threads of the process.

00:22.630 --> 00:27.910
And when I say communication, it simply means exchange of data between the threads.

00:28.390 --> 00:33.280
So a big software system may have built as a multi threaded software, right?

00:33.280 --> 00:38.860
And the threads of this multi threaded software may require exchange data with one another.

00:38.860 --> 00:45.310
So it is quite possible that you build a very big, huge software which is divided into independent

00:45.310 --> 00:48.700
modules, say M1, M2 and M3.

00:48.700 --> 00:55.150
And these modules, M1, M2, M3 are running as separate threads of the same process.

00:56.010 --> 01:02.940
And let us say that these modules, M1, M2 and M3 are nothing, but these are three independent threads

01:02.940 --> 01:03.900
of the same process.

01:03.930 --> 01:05.190
P Right.

01:06.270 --> 01:14.370
Now, it may be required that module M1 may want to send some data to module M2 and M2 may want to send

01:14.370 --> 01:17.610
some data to module M3 and so on.

01:17.610 --> 01:18.360
Right.

01:18.390 --> 01:23.370
This is very normal logistics of a typical big software program, right?

01:23.400 --> 01:29.640
So famous IPC techniques are usually used to set up data exchange between the processes.

01:29.670 --> 01:36.450
So note that there are various IPC techniques which exist today in order to facilitate communication

01:36.450 --> 01:43.620
between the processes and technically, nothing is stopping you from using these IPC techniques to facilitate

01:43.620 --> 01:45.570
communication between the threads.

01:45.600 --> 01:46.350
Right.

01:46.380 --> 01:51.870
So you must have come across the names like sockets, message queues, pipes, shared memory.

01:51.900 --> 01:58.290
These are all the tools that your typical operating system provides to set up the communication between

01:58.290 --> 02:00.240
processes running on the system.

02:00.240 --> 02:00.930
Right.

02:01.870 --> 02:08.140
But when it comes to set up communication between threads, technically nothing is stopping you from

02:08.140 --> 02:12.130
using these techniques to facilitate communication between threads.

02:12.340 --> 02:18.070
You can use any of these techniques for data exchange between the threads of the same process, but

02:18.070 --> 02:20.580
still for inter thread communication.

02:20.590 --> 02:24.370
IPC technique is not the recommended way for data exchange.

02:25.080 --> 02:30.990
In fact, the communication between threads is preferred through callback or function pointers.

02:30.990 --> 02:33.380
And the reason is very clear for this.

02:33.390 --> 02:38.400
The reason is that that the communication through callbacks or function pointers is very fast.

02:38.640 --> 02:40.200
In this type of communication.

02:40.200 --> 02:44.940
There is actually no transfer of data, but there is a transfer of computation.

02:44.940 --> 02:49.290
So we will going to understand this point elaborately in the next lecture video.

02:50.860 --> 02:54.040
In communication through function pointers or callbacks.

02:54.040 --> 02:59.500
There is absolutely no need for the special attention required from the kernel or operating system.

02:59.530 --> 03:04.930
This type of communication is completely and independently supported in the user space.

03:04.960 --> 03:10.660
This does not require any underlying operating system support and therefore no kernel resources need

03:10.660 --> 03:17.410
to be explicitly created to carry out communication between the two threads of the same process using

03:17.410 --> 03:19.260
callbacks or function pointers.

03:19.270 --> 03:24.820
Because at the end of the day, callbacks and function pointer is nothing but it is the invocation of

03:24.820 --> 03:25.630
the function.

03:25.630 --> 03:26.320
Right.

03:27.240 --> 03:34.320
And one function invoke another function completely in the user space without the assistance of underlying

03:34.350 --> 03:36.040
operating system or kernel.

03:36.060 --> 03:36.780
Right.

03:38.600 --> 03:41.450
Unless, of course, your function to is a system call.

03:42.460 --> 03:48.820
So now in the next lecture video, let us focus on this point that communication using callbacks or

03:48.820 --> 03:55.540
function pointers do not involve any actual transfer of data, but in fact it involves the transfer

03:55.540 --> 03:57.100
of computation itself.
