So guys, we were going to discuss thread barrier, which is another data structure for thread synchronization,
right?
So in this section we will going to discuss what thread barrier is, what is its use case, and then
finally we will going to implement this data structure.
So as you can see, picture on the right hand side, it gives you an overall idea regarding what thread
barrier is all about, right?
So thread barrier is a thread synchronization data structure which blocks all the threads at a particular
line of code until some specified number of threads arrive at that barrier point.
Right.
So the definition is quite simple in cases where you must wait for a number of tasks to be completed
before an overall task can proceed.
Barrier synchronization can be used.
So this is a situation where you will use thread barrier like data structure for thread synchronization.
If you want your software or application to wait until all the currently running threads finish their
task and you want your application to continue.
Only when all the running tasks has finished their execution, then in such a situation you must use
thread barrier.
So one practical use case where you can witness the functioning of the thread barrier is that if you
have ever used Iddm, it is called Internet Download Manager, which is a software to download big files
from the internet.
Right.
So this application actually downloads a bigger file in the context of multiple threads where each thread
download a portion of the file independently and when all the threads have completed downloading of
the file, then only the internet download manager reports that the download is success.
Right.
So for example, let us suppose that you have a big file which is present on the internet.
Let us say that this is some video file and let's say the size of this file is 112MB, right?
Now you try to download this video file using internet download manager.
So what this Internet download manager application does is that it divides this file into some independent
parts.
Let us say we divide this file into part one, part two and part three, and then this Internet download
manager launches independent threads which download each independent part of the file in parallel.
Right.
The three threads run concurrently or in parallel on all the available CPUs on the machine.
Right?
So this accelerates the process of downloading a file, an internet download manager as an application,
then aggregate all the pieces together only when all the three threads have actually downloaded their
respective chunk of file.
Right.
So you can see that the internal download manager as an application have to wait until all the threads
have completed their task and when all the threads have completed their task, that is downloading their
respective chunk of a file, then only internet download manager as an application, concatenate or
aggregate all the pieces together to announce to the user that the file downloading has been finished.
Right.
So this is a typical case where thread barrier can be used.
Now I don't know whether internet download manager really use thread barrier or not, but I see it as
a potential use case in which one would like to use thread barrier.
Right.