WEBVTT

00:05.090 --> 00:12.200
So guys, we were going to discuss thread barrier, which is another data structure for thread synchronization,

00:12.200 --> 00:13.010
right?

00:13.100 --> 00:18.290
So in this section we will going to discuss what thread barrier is, what is its use case, and then

00:18.290 --> 00:21.800
finally we will going to implement this data structure.

00:22.190 --> 00:28.490
So as you can see, picture on the right hand side, it gives you an overall idea regarding what thread

00:28.490 --> 00:30.890
barrier is all about, right?

00:32.300 --> 00:38.180
So thread barrier is a thread synchronization data structure which blocks all the threads at a particular

00:38.180 --> 00:43.880
line of code until some specified number of threads arrive at that barrier point.

00:43.910 --> 00:44.670
Right.

00:44.690 --> 00:51.710
So the definition is quite simple in cases where you must wait for a number of tasks to be completed

00:51.710 --> 00:54.440
before an overall task can proceed.

00:54.470 --> 00:57.250
Barrier synchronization can be used.

00:57.260 --> 01:03.890
So this is a situation where you will use thread barrier like data structure for thread synchronization.

01:04.250 --> 01:10.260
If you want your software or application to wait until all the currently running threads finish their

01:10.260 --> 01:14.610
task and you want your application to continue.

01:14.610 --> 01:20.340
Only when all the running tasks has finished their execution, then in such a situation you must use

01:20.340 --> 01:21.300
thread barrier.

01:21.570 --> 01:27.450
So one practical use case where you can witness the functioning of the thread barrier is that if you

01:27.450 --> 01:34.890
have ever used Iddm, it is called Internet Download Manager, which is a software to download big files

01:34.890 --> 01:36.150
from the internet.

01:36.150 --> 01:36.900
Right.

01:37.690 --> 01:44.620
So this application actually downloads a bigger file in the context of multiple threads where each thread

01:44.620 --> 01:50.530
download a portion of the file independently and when all the threads have completed downloading of

01:50.530 --> 01:55.850
the file, then only the internet download manager reports that the download is success.

01:55.870 --> 01:56.650
Right.

01:56.890 --> 02:01.600
So for example, let us suppose that you have a big file which is present on the internet.

02:01.600 --> 02:11.350
Let us say that this is some video file and let's say the size of this file is 112MB, right?

02:11.440 --> 02:15.730
Now you try to download this video file using internet download manager.

02:15.730 --> 02:23.860
So what this Internet download manager application does is that it divides this file into some independent

02:23.860 --> 02:24.280
parts.

02:24.280 --> 02:31.120
Let us say we divide this file into part one, part two and part three, and then this Internet download

02:31.120 --> 02:39.770
manager launches independent threads which download each independent part of the file in parallel.

02:39.980 --> 02:40.730
Right.

02:40.760 --> 02:47.420
The three threads run concurrently or in parallel on all the available CPUs on the machine.

02:47.420 --> 02:48.230
Right?

02:48.230 --> 02:55.430
So this accelerates the process of downloading a file, an internet download manager as an application,

02:55.430 --> 03:02.210
then aggregate all the pieces together only when all the three threads have actually downloaded their

03:02.210 --> 03:03.920
respective chunk of file.

03:04.100 --> 03:04.880
Right.

03:06.110 --> 03:12.860
So you can see that the internal download manager as an application have to wait until all the threads

03:12.860 --> 03:18.590
have completed their task and when all the threads have completed their task, that is downloading their

03:18.590 --> 03:26.030
respective chunk of a file, then only internet download manager as an application, concatenate or

03:26.030 --> 03:32.090
aggregate all the pieces together to announce to the user that the file downloading has been finished.

03:32.210 --> 03:33.050
Right.

03:33.050 --> 03:37.160
So this is a typical case where thread barrier can be used.

03:37.190 --> 03:43.520
Now I don't know whether internet download manager really use thread barrier or not, but I see it as

03:43.520 --> 03:48.110
a potential use case in which one would like to use thread barrier.

03:48.110 --> 03:48.890
Right.
