操作系统多线程实现_操作系统中的线程实现

操作系统多线程实现

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.mzph.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…