操作系统多线程实现_操作系统中的线程实现
操作系統(tǒng)多線程實(shí)現(xiàn)
Each process has an address space. There is one thread of control in every traditional OS. Sometimes, it is viable to have multiple threads of control in the similar address space which is running in quasi-parallel. Though they were separate processes they have same shared address space.
每個(gè)進(jìn)程都有一個(gè)地址空間。 每個(gè)傳統(tǒng)的OS中都有一個(gè)控制線程 。 有時(shí),在類似地址空間中以準(zhǔn)并行運(yùn)行方式具有多個(gè)控制線程是可行的。 盡管它們是獨(dú)立的進(jìn)程,但它們具有相同的共享地址空間。
Threads are used in case of multiple applications running at the same particular time few activities might block from one point of time to another. By decomposition into multiple threads that are running in quasi-parallel, the programming model becomes simpler and easier.
在多個(gè)應(yīng)用程序在同一特定時(shí)間運(yùn)行的情況下使用線程 ,很少有活動(dòng)可能從一個(gè)時(shí)間點(diǎn)阻塞到另一個(gè)時(shí)間點(diǎn)。 通過分解成多個(gè)準(zhǔn)并行運(yùn)行的線程,編程模型變得越來越簡單。
The new element can only be added with threads. This ability to share the same address space and data is essential for some applications.
新元素只能與線程一起添加。 對(duì)于某些應(yīng)用程序,共享相同地址空間和數(shù)據(jù)的能力至關(guān)重要。
There are no resources attached to threads. Processes are difficult to create and destroy but threads, on the other hand, can be easily created and destroyed. Creating a thread isabout100x faster than creating a process.
沒有資源附加到線程。 進(jìn)程很難創(chuàng)建和銷毀,但另一方面,線程卻可以輕松創(chuàng)建和銷毀。 創(chuàng)建線程的速度比創(chuàng)建進(jìn)程快100倍。
The thread has program counter(pc)to keep the track of the instruction to be executed next. It also has registers to hold the presently working variables. There is a stack to store the execution history there is one frame for one procedure called but not still returned from.
該線程具有程序計(jì)數(shù)器(pc),以跟蹤下一條要執(zhí)行的指令。 它還具有用于保存當(dāng)前工作變量的寄存器。 有一個(gè)堆棧可以存儲(chǔ)執(zhí)行歷史記錄,對(duì)于一個(gè)被調(diào)用但尚未返回的過程,只有一幀。
Threads are scheduled for the implementation or execution on CPU.
線程被安排在CPU上實(shí)現(xiàn)或執(zhí)行 。
There are four states of a thread:
線程有四種狀態(tài):
Running
跑步
Blocked
受阻
Read
讀
Terminated
已終止
The stack of each thread is as follows:
每個(gè)線程的堆棧如下:
There are two ways of implementing a thread package:
有兩種實(shí)現(xiàn)線程包的方法:
In user space
在用戶空間
In kernel
在內(nèi)核中
Threads implementation in the user space
用戶空間中的線程實(shí)現(xiàn)
In this model of implementation, the threads package entirely in user space, the kernel has no idea about it. A user-level threads package can be executed on an operating system that doesn't support threads and this is the main advantage of this implementation model i.e. Threads package in user space.
在這種實(shí)現(xiàn)模型中,線程完全封裝在用戶空間中,內(nèi)核對(duì)此一無所知。 用戶級(jí)線程包可以在不支持線程的操作系統(tǒng)上執(zhí)行,這是此實(shí)現(xiàn)模型的主要優(yōu)點(diǎn),即用戶空間中的線程包。
Threads implementation in the kernel
內(nèi)核中的線程實(shí)現(xiàn)
In this method of implementation model, the threads package completely in the kernel. There is no need for any runtime system. To maintain the record of all threads in the system a kernel has a thread table.
在這種實(shí)現(xiàn)模型方法中,線程完全封裝在內(nèi)核中。 不需要任何運(yùn)行時(shí)系統(tǒng)。 為了維護(hù)系統(tǒng)中所有線程的記錄,內(nèi)核具有線程表。
A call to the kernel is made whenever there is a need to create a new thread or destroy an existing thread. In this, the kernel thread table is updated.
每當(dāng)需要?jiǎng)?chuàng)建新線程或銷毀現(xiàn)有線程時(shí),都會(huì)調(diào)用內(nèi)核。 在此,內(nèi)核線程表被更新。
Other two methods are as follows:
其他兩種方法如下:
Hybrid implementation
混合實(shí)施
Scheduler activation
調(diào)度程序激活
Hybrid implementation
混合實(shí)施
In this implementation, there is some set of user-level threads for each kernel level thread that takes turns by using it.
在此實(shí)現(xiàn)中,每個(gè)使用它輪流使用的內(nèi)核級(jí)線程都有一組用戶級(jí)線程。
Scheduler activation
調(diào)度程序激活
The objective of this scheduler activation work is to replicate the working or function of kernel threads, but with higher performance and better flexibility which are usually related to threads packages which are implemented in userspace.
調(diào)度程序激活工作的目的是復(fù)制內(nèi)核線程的工作或功能,但具有更高的性能和更好的靈活性,通常與在用戶空間中實(shí)現(xiàn)的線程包有關(guān)。
Pop-up threads
彈出線程
In this system, a new thread is created just to handle the message as soon as the arrival of a message takes place and thus it is called pop up thread.
在此系統(tǒng)中,將創(chuàng)建一個(gè)新線程來僅在消息到達(dá)時(shí)處理消息,因此將其稱為彈出線程。
The benefit of this pop-up thread is that they are brand new and hence don’t need any stacks or history registers, etc. that must be restored. Each pop-up thread is fresh and new and is similar to all other pop up threads. This is the reason why a pop-up thread can be created very quickly. The incoming message to be processed is given to the new thread.
此彈出線程的好處是它們是全新的,因此不需要任何必須還原的堆?;驓v史記錄寄存器等。 每個(gè)彈出線程都是新的,并且與所有其他彈出線程相似。 這就是可以很快創(chuàng)建彈出線程的原因。 要處理的傳入消息將提供給新線程。
The result of using such a thread is mainly that the latency between the arrival of the message and the start of processing is made very short.
使用這種線程的結(jié)果主要是使消息到達(dá)和處理開始之間的等待時(shí)間非常短。
翻譯自: https://www.includehelp.com/operating-systems/thread-Implementation.aspx
操作系統(tǒng)多線程實(shí)現(xiàn)
總結(jié)
以上是生活随笔為你收集整理的操作系统多线程实现_操作系统中的线程实现的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: 颐和园上午的票下午能进吗
 - 下一篇: java 检查目录是否存在_如何检查Ja