Multithreading Models & Hyperthreading

preview_player
Показать описание
Operating System: Multithreading Models & Hyperthreading
Topics discussed:
1) Multithreading Models.
2) Many-to-one model.
3) One-to-one Model.
4) Many-to-many Model.
5) Hyperthreading or Simultaneous Multithreading.

Follow Neso Academy on Instagram: @nesoacademy

Music:
Axol x Alex Skrindo - You [NCS Release]

#OperatingSystemByNeso #os #OperatingSystem #Multithreading #Hyperthreading
Рекомендации по теме
Комментарии
Автор

I searched many websites and videos to learn Threading and thank GOD I found the best one in your channel. Thanks a lot for your efforts.

ksvprasad
Автор

Here is what I understood:
There are two types of Threads:
-User Threads which managed in user space without kernel support
-Kernel Threads where managed directly in kernel
And these two threads function together there must exist a relationship between them. And the relationship is called Multithreading. There are three ways to establish this relationship, each one having their own advantages and disadvantages.

Many to one model: Many user threads to one kernel thread. Threads management happens in user level so it's efficient. However, if one of those user thread makes blocking system call then the kernel thread would be blocked which is connected to other user threads. In other words all other user threads would be blocked, ultimately the entire process would be blocked (considering all those threads associated with same process). In addition, only one thread can access to kernel at a time, it cannot utilize multi-processors fully. Because one kernel thread can run only one of those processors.

One to one model: For one user thread there exists one kernel thread. This model basically overcome disadvantages of many to one model such as multiprocessing thanks to multiple kernel threads (for each user thread) and avoiding risk of blocking entire process when one of the thread calls system blocking. Even so it has its own disadvantages including having obliged to create a kernel thread for each user thread which can be costly. Also having too many kernel threads can affect the performance of the application because one kernel thread can run on only one processor. So if you're having multiprocessor system, let's say 4 cores, then creating more than 4 kernel thread causes overhead and burden to the application. Because of this usually applications set limits on how many threads can be created.

Many to many model: Many user threads multiplexes to equal or less kernel threads.
Definition of multiplex: system or signal involving simultaneous transmission of several messages along a single channel of communication.
The number of kernel may be specified depending on the machine or the application. Developer can create user level threads as many as they want. Even after user thread calls blocking system, the entire process won't blocked. Basically it's the most ideal model among all three.

Hyperthreading or Simultaneous Multithreading: It's basically whether your system has logical processors. Logical processor is the doubled version of your physical processor (cores). If I have 4 physical processor then I might have 8 logical processor, so my machine can process 8 threads concurrently. To see whether your system supports logical processors (windows) go to cmd and type wmic then type CPU Get NumberOfCores, NumberOfLogicalProcessors. If two numbers are the same then your system doesn't support hyperthreading.

DaiMoscv
Автор

/* Omg, this is the first time when I applied my theoretically knowledge of operating system in my Life */

gatecomputerscience
Автор

In some systems (especially real-time systems), an asynchronous connection exists between user and kernel threads. That is, a user thread can make a request to a kernel thread, and that request is queued to the kernel thread. The user thread can then continue processing while the kernel thread does its processing (in parallel on a multi-core system). When the kernel finishes, it sends the results to the user thread (either with a callback function of queuing the results to the user thread).

This type of user/kernel connection allows a one-to-many relationship. The user thread can be connected to many kernel threads. This relationship also can change the many-to-many relationship. A user thread can connect to many kernel cores, while a kernel thread can connect to many user threads. This is the most powerful of models but also the most difficult to implement.

With this many-to-many model, a user thread does not block when a kernel thread does. Each user thread can do more work, increasing the amount of processing a multicore system can do. In addition, each kernel thread can be specialized, making each kernel thread simpler and smaller. Programming to take advantage of these capabilities is more difficult than in the other models.

Let me give an example - crypto-mining. The engineer creates many user threads to perform the crypto-mining calculations. One kernel thread delivers the next piece to user threads while another kernel thread receives and records the results. The user thread requests the next piece and waits until it shows up. When it gets that piece, it requests the next (or even several pieces) and then starts processing the piece it has. When it completes, it sends the results to the record thread, gets the next piece off of its queue, and starts processing again. In this example, user threads will process data almost 100% of the time. Kernel threads do not stall user threads, and user threads do not stall kernel threads. However, user and kernel threads must implement these inter-process queues (a non-trivial exercise).

SidonYT
Автор

In Linux world, the word "kernel thread" is used to refer to threads running in kernel space, like ksoftirqd, kworker, kswapd etc. which can be shown when you type "ps aux" in the terminal.
In this video, "kernel thread" is used as threads managed as "struct task_struct" in the linux source code.
User threads on the other hand are like pseudo-threads implemented in userspace, where each user threads are assigned memory area for its stack and CPU resisters saved on pseudo-context-switch, triggered by userspace libraries like tokio (popular asynchronous runtime in Rust).
Hyperthreading is a totally different concept, where the CPU shows the OS an illusion that it has more threads than its cores (of course OS can be informed whether hyperthreading is activated or not).

long-live-linux
Автор

Thankyou for the video But there is a correction:

Although many-to-many model posses no disadvantages of the other models, in practice it is difficult to implement. Also because modern systems has increasing number of cores (and features like hyper-threading), the kernel thread limitation can be removed. Because of these reasons, most OSs are using the *One-to-One* model instead.

midhunrajr
Автор

thanks a bunch, guy! you're providing quality unmatched education, here on yt for free. GOD bless:) ❤❤

ayushiydvKG
Автор

I have no words to appreciate you Sir, such a best way of teaching.🥰

parkashkumar
Автор

The video is amazing, yet...there is still the open question, how the HyperThreading really works, and is it really a performance-increase along with the the question: how do the L1 and L2 -caches get utilized by the logical-threads then?

chillyvanilly
Автор

It's so cool to see what is going inside.

snape
Автор

best yt channel for preparing subjects and getting concepts cleared

darshanwalunj
Автор

What an amazing explanation Great piece of work

shivushankar
Автор

Thank you sir... Your videos are really helpfull.It helps me to understand to topics of book...

rifatara
Автор

Tq sir.... For more information rather than our syllabus... ☺☺☺

priyankabehera
Автор

Hi Nesoacademy... When your channel was hacked and we shifted to a new channel then i too put many tweets to bring back your channel..We were lucky that we got back on that time...
I want to say that if you will be providing notes then it will be good for us to keep track...and revise things easily...
it's a huge request to provide these notes of the videos.
thank you

abhishekjaiswal
Автор

1) Multi-threading
- 2 types of threads: user thread and kernel thread
- User thread run on top of the OS and is not support by the OS
- Kernel thread is support by the OS
- A relationship must exist between these 2 threads, called multithreading
- 3 types of relationships: many to one, one to one and many to many
- Many to one: multiple user threads are linked to only one kernel thread. When an user thread make a blocking system call, it will block the other threads or the whole process.
- One to one: one user thread is linked to one kernel thread. This model can solve the many to one problem, but the number of kernel threads is limited, so it limits the user threads created.
- Many to many: multiple user thread are linked to an equal or less than number of kernel threads. So when an user thread makes a blocking system call, the other user threads will be scheduled to another kernel thread

2) Hyperthreading or Simultaneous Multithreading (SMT)

- Hyperthreaded systems allows their processor core to become multiple logically processors

hoangminhchau
Автор

If you want to check if your Windows machine has hyper-threading capability, you can search for system information in the search bar. In the system summary, you can see how many cores and also how many logical processors your machine has

aquadap
Автор

I will get subscription of your neso app but there are nothing facility to discuss with faculty so please help me sir i have one question
can a multithreaded solution using multiple user-level threads achieve better performance on a multiprocessor system than on single processor system

Plzz sir explain me in detail

TechnoyashBro
Автор

thank you very much sir for this video

saddamahmad
Автор

Bro this is not fair because I was searching for videos like this for my exam but not found, but u uploaded it today but I have completed my exam just 1 day back from the date u have uploaded .
So sad 😞😞😞😞

cinemadtv