操作系統多線程實現_操作系統中的線程實現

操作系統多線程實現

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.

每個進程都有一個地址空間。 每個傳統的OS中都有一個控制線程 。 有時,在類似地址空間中以準并行運行方式具有多個控制線程是可行的。 盡管它們是獨立的進程,但它們具有相同的共享地址空間。

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.

在多個應用程序在同一特定時間運行的情況下使用線程 ,很少有活動可能從一個時間點阻塞到另一個時間點。 通過分解成多個準并行運行的線程,編程模型變得越來越簡單。

The new element can only be added with threads. This ability to share the same address space and data is essential for some applications.

新元素只能與線程一起添加。 對于某些應用程序,共享相同地址空間和數據的能力至關重要。

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.

沒有資源附加到線程。 進程很難創建和銷毀,但另一方面,線程卻可以輕松創建和銷毀。 創建線程的速度比創建進程快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.

該線程具有程序計數器(pc),以跟蹤下一條要執行的指令。 它還具有用于保存當前工作變量的寄存器。 有一個堆棧可以存儲執行歷史記錄,對于一個被調用但尚未返回的過程,只有一幀。

Threads are scheduled for the implementation or execution on CPU.

線程被安排在CPU上實現或執行

There are four states of a thread:

線程有四種狀態:

  1. Running

    跑步

  2. Blocked

    受阻

  3. Read

  4. Terminated

    已終止

The stack of each thread is as follows:

每個線程的堆棧如下:

thread implementation 1

There are two ways of implementing a thread package:

有兩種實現線程包的方法:

  1. In user space

    在用戶空間

  2. In kernel

    在內核中

Threads implementation in the user space

用戶空間中的線程實現

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.

在這種實現模型中,線程完全封裝在用戶空間中,內核對此一無所知。 用戶級線程包可以在不支持線程的操作系統上執行,這是此實現模型的主要優點,即用戶空間中的線程包。

Threads implementation in the kernel

內核中的線程實現

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.

在這種實現模型方法中,線程完全封裝在內核中。 不需要任何運行時系統。 為了維護系統中所有線程的記錄,內核具有線程表。

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.

每當需要創建新線程或銷毀現有線程時,都會調用內核。 在此,內核線程表被更新。

Other two methods are as follows:

其他兩種方法如下:

  • Hybrid implementation

    混合實施

  • Scheduler activation

    調度程序激活

Hybrid implementation

混合實施

In this implementation, there is some set of user-level threads for each kernel level thread that takes turns by using it.

在此實現中,每個使用它輪流使用的內核級線程都有一組用戶級線程。

Scheduler activation

調度程序激活

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.

調度程序激活工作的目的是復制內核線程的工作或功能,但具有更高的性能和更好的靈活性,通常與在用戶空間中實現的線程包有關。

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.

在此系統中,將創建一個新線程來僅在消息到達時處理消息,因此將其稱為彈出線程。

thread implementation 2

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.

此彈出線程的好處是它們是全新的,因此不需要任何必須還原的堆棧或歷史記錄寄存器等。 每個彈出線程都是新的,并且與所有其他彈出線程相似。 這就是可以很快創建彈出線程的原因。 要處理的傳入消息將提供給新線程。

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.

使用這種線程的結果主要是使消息到達和處理開始之間的等待時間非常短。

翻譯自: https://www.includehelp.com/operating-systems/thread-Implementation.aspx

操作系統多線程實現

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/378562.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/378562.shtml
英文地址,請注明出處:http://en.pswp.cn/news/378562.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

mysql怎么消除冗余,mysql剔除冗余數據

mysql刪除冗余數據-- -- 1. 查詢冗余數據SELECT t.id FROM t_lifeservice_orders t WHERE t.orderStatus 2 GROUP BY t.channelCode, t.orderNum, t.orderStatus HAVING COUNT(t.orderStatus) > 1;-- -- 2. 定義刪除冗余數據存儲過程DROP PROCEDURE IF EXISTS proc_delete_…

04-圖像的形狀繪制

一、線段繪制 cv2.line(dst,(100,100),(400,400),(0,0,255),2,cv2.LINE_AA) 參數一:目標圖片數據 參數二:當前線段繪制的起始位置(也就是兩點確定一條直線) 參數三:當前線段繪制的終止位置(也就是兩點確定…

(1-e^(-j5w))/(1-e^(-jw))=e^(-j2w)*sin(5w/2)/sin(w/2)的證明過程

問題出現:《數字信號處理第三版》第90頁劉順蘭版 最后一步怎么得到的? 思路:觀察答案,有一個自然對數項。關鍵就是如何提取出這一項。 我的證明過程如下: 參考鏈接: 【和差化積】

php 移植 arm 精簡,php5.4.5移植到arm-linux摘要,lighttpd配置

php5.4.5移植到arm-linux摘要.因為有嵌入WEB服務的需求,再常識了N多的開源的嵌入服務后最終選擇了lighttpd.Apache太大支了,而且在arm上對swf的支持不好.其他的都不怎么理想.lighttpd的移植過程就省略了。這里只摘要了PHP移植,采用fastcgi與lighttpd 協作…

05-圖像的美化

一、彩色圖片直方圖 cv2.calcHist([image],[0],None,[256],[0.0,255.0]) 該方法的所有參數都必須用中括號括起來!!! 參數一:傳入的圖片數據 參數二:用于計算直方圖的通道,這里使用的是灰度直方圖&#xff…

java 檢查目錄是否存在_如何檢查Java目錄是否存在?

java 檢查目錄是否存在We are using the File class that is an abstract representation of file and directory path. To check if a directory exists we have to follow a few steps: 我們正在使用File類 ,它是文件和目錄路徑的抽象表示。 要檢查目錄是否存在&a…

Eclipse for android 中設置java和xml代碼提示功能(轉)

1、設置 java 文件的代碼提示功能 打開 Eclipse 依次選擇 Window > Preferences > Java > Editor - Content Assist > Auto activation triggers for Java ,設置框中默認是一個點, 現在將它改為: 以下為引用內容: .a…

MySQL 定時器EVENT學習

MySQL 定時器EVENT學習 MySQL從5.1開始支持event功能,類似oracle的job功能。有了這個功能之后我們就可以讓MySQL自動的執行數據匯總等功能,不用像以前需要操作的支持了。如linux crontab功能 。 創建測試表CREATE TABLE t( v VARCHAR(100) NOT NULL…

如何利用FFT(基2時間以及基2頻率)信號流圖求序列的DFT

直接用兩個例子作為模板說明: 利用基2時間抽取的FFT流圖計算序列的DFT 1、按照序列x[k]序號的偶奇分解為x[k]和x2[k],即x1[k]{1,1,2,1}, x2[k]{-1,-1,1,2} 2、畫出信號流圖并同時進行計算 計算的時候需要參考基本蝶形單元: 關鍵在于 (WN) k…

matlab4.0,matlab?4.0

4.1fort-9:0.5:9if(t>0)y-(3*t^2)5;fprintf(y%.2ft%.2f\n,y,t);elsey(3*t^2)5;fprintf(y%.2ft%.2f\n,y,t);endend編譯結果:y248.00t-9.00y221.75t-8.50y197.00t-8.00y173.75t-7.50y152.00t-7.00y131.75t-6.50y113.00t-6.00y95.75t-5.50y80.00t-5.00y65.75t-4.50y…

圖形學 射線相交算法_計算機圖形學中的陰極射線管

圖形學 射線相交算法陰極射線管 (Cathode Ray Tube) Ferdinand Barun of Strasbourg developed the cathode ray tube in the year 1897. It used as an oscilloscope to view and measure some electrical signals. But several other technologies exist and solid state mov…

Constructor總結

一個類如果沒有構造那么系統為我們在背后創建一個0參數的構造,但是一旦我們創建了但參數的構造,那么默認的構造就沒了。 View Code 1 using System;2 using System.Collections.Generic;3 using System.Linq;4 using System.Text;5 6 namespace Console…

Python連接MySQL及一系列相關操作

一、首先需要安裝包pymysql(python3所對應) 我使用的是Anaconda全家桶,打開cmd,進入Anaconda下的Scripts文件夾下輸入命令:pip install pymysql進行下載安裝 二、我使用的編譯器為Anaconda所帶的Jupyter Notebook 1,在mysql中…

微機原理—可編程計數器/定時器8253概念詳解

目錄前言【1】定時處理方法1、定時的方法:2、定時和計數器【2】8253計數/定時器1、特點:2、芯片引腳以及電路:3、連接方式:4、工作原理:5、寄存器配置a、初始化操作(三個通道單獨初始化)b、讀出…

php靜態分析工具window,window_SpeedPHP框架核心調試工具,在日常的編程開發當中,開發 - phpStudy...

SpeedPHP框架核心調試工具在日常的編程開發當中,開發者經常會使用到對變量的調試,而sp框架提供的變量調試輸出函數——dump正好滿足了變量調試的需求。下面來介紹一下dump函數的使用方法。dump —— 變量格式化輸出函數用法:dump($vars, $out…

python 溫度轉換程序_Python程序將米轉換為碼

python 溫度轉換程序There are many problems where we have to calculate the distance in yards at the end but initially, the measurements are given in meters. So for such type of problems, the solution is converting the initial parameters into yards and then …

Oracle轉Sqlserver 記錄

使用了微軟的SSMA幫忙,但是目前只有表能幫忙轉,其他的還是要手動改,- - oracle 可以這樣查詢AppServiceInfoaspdb ,調用其他庫的表。SQL是: aspdb.dob.AppServiceInfo si數據庫需要和 aspdb ASPDB_Capacity 在siinf…

形參與實參在函數中的傳遞

#include <iostream> #include <cstring> using namespace std; void myFun(int a[]); int main() {int a[10];cout<<"aaa"<<sizeof(a)<<endl;//40 int為4&#xff0c;a為10個int&#xff0c;故為40cout<<"yy"<<…

帶你走進緩存世界

我們搞程序的多多少少都了解點算法。總體來講&#xff0c;算法是什么&#xff1f;算法就是“時間”和“空間”的互換策略。我們常常考究一個算法的時間復雜度或空間復雜度&#xff0c;如果我們有絕對足夠的時間或空間&#xff0c;那么算法就不需要了&#xff0c;可惜這種條件是…

霍夫碼編碼(一種不等長,非前綴編碼方式)

霍夫曼編碼是一種不等長非前綴編碼方式&#xff0c;于1951年由MIT的霍夫曼提出。 用于對一串數字/符號編碼獲取最短的結果&#xff0c;獲取最大的壓縮效率。 特點&#xff1a;不等長、非前綴 等長式編碼 等長編碼&#xff0c;意思是對出現的元素采用相同位數的序號進行標定&a…