操作系统多线程实现

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:

每个线程的堆栈如下:

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.

在此系统中,将创建一个新线程来仅在消息到达时处理消息,因此将其称为弹出线程。

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

操作系统多线程实现

操作系统多线程实现_操作系统中的线程实现相关推荐

  1. 操作系统饥饿现象_操作系统常见面试题

    1.进程的常见状态?以及各种状态之间的转换条件? 就绪:进程已处于准备好运行的状态,即进程已分配到除CPU外的所有必要资源后,只要再获得CPU,便可立即执行. 执行:进程已经获得CPU,程序正在执行状 ...

  2. java 多线程池_Java项目中,线程池中线程数量太大会有什么影响?

    简单说一下吧!拿我们生活中非常常见的一例子来说:并不是人多就能把事情做好,增加了沟通交流成本.你本来一件事情只需要3个人做,你硬是拉来了6个人,会提升做事效率嘛?我想并不会. 线程数量过多的影响也是和 ...

  3. Java多线程编程(1)--Java中的线程

    一.程序.进程和线程   程序是一组指令的有序集合,也可以将其通俗地理解为若干行代码.它本身没有任何运行的含义,它只是一个静态的实体,它可能只是一个单纯的文本文件,也有可能是经过编译之后生成的可执行文 ...

  4. 操作系统饥饿现象_操作系统心得体会

    一.操作系统 1.基本概念 操作系统简称OS,是配置在计算机硬件上的第一层软件,它能够有效的组织和管理计算机系统中的硬件和软件资源,合理的组织计算机工作流程,控制程序的执行,并向用户提供各种服务功能. ...

  5. c++ map初始化_Java多线程 未完成初始化--构造方法中新建线程

    对象未完成初始化就把对象提供给外界--构造方法中新建线程 如下的代码 ,演示了 构造方法中新建线程 . 例如给map赋值. 之后在main方法调用中, 尝试获取map中,对应key的值 package ...

  6. 操作系统 系统开销比率_操作系统中的最高响应比率下一个(HRRN)调度

    操作系统 系统开销比率 操作系统中的HRRN调度是什么? (What is HRRN Scheduling in Operating System?) HRRN is the abbreviation ...

  7. 操作系统文件分配策略_操作系统中的文件分配方法

    操作系统文件分配策略 分配方法 (Allocation Method) The allocation method defines how the files are stored in the di ...

  8. 操作系统饥饿现象_操作系统中的饿死现象怎样理解?

    什么是进程的饥饿和饿死? 在一个动态系统中,资源请求与释放是经常性发生的进程行为.对于每类系统资源,操作系统需要确定一个分配策略,当多个进程同时申请某类资源时,由分配策略确定资源分配给进程的次序. 资 ...

  9. python操作系统课程设计_操作系统课程设计.pdf

    计算机科学与通信工程学院 操作系统课程设计报告 题目:linux系统下实现PV 操作 班级: 软件工程1401 姓名: 吴帅帅 学号: 3140608020 指导老师: 牛德姣 2016 年12 月2 ...

最新文章

  1. DEDECMS v5.5 GBK Final 的一个鸡肋漏洞
  2. jQuery+ajax中,让window.open不被拦截(转)
  3. html选择器_HTML的id选择器类选择器
  4. Android学习笔记(二三): 多页显示-Flipper的使用
  5. UI组件:ext、JqueryEasyUI、miniui、dhtmlx及自定义页面
  6. 百信银行基于 Apache Hudi 实时数据湖演进方案
  7. python封装模块_Python练手,封装日志模块,v2
  8. swiper鼠标hover停止自动轮播_swiper滑块组件
  9. (30)SPI接口调试丢数据解决(FPGA不积跬步101)
  10. Vue工程报错解决方案Warn:import Vue from “vue“;
  11. k8s中的endpoint
  12. java怎么输出liststring_春招|春招实习上岸,分享面筋回报社区(Java、Python)...
  13. 一个计算机系统配置有3台打印机,我们是局域网3站点 3台电脑共享一个打印机 3台电脑相同的系统 打印参数也设置完全一样 但是打印出来的效果却不同 请问什么原因?需要怎么设置?...
  14. 2021年复盘总结发现了C站博主缺少的赚钱之路
  15. setw和width
  16. 福禄克FLUKE OptiFiber Pro HDR OTDR光时域反射(OTDR)测试仪OFP2-100-S
  17. t分布f分布与样本均值抽样分布_常见的统计分布--数据分析
  18. sonar代码审查问题分析
  19. Hibernate的DetachedCriteria使用(含Criteria)转载
  20. MinGW编译log4cpp

热门文章

  1. 漏洞工具:nmap和nessus
  2. Linux中重要文件
  3. jwt重放攻击_4个点搞懂JWT、JWS、JWE
  4. 鼠标拖动改变DIV等网页元素的大小的最佳实践
  5. 使用ant design Pro开发项目的小结
  6. Pyechart:30分钟学会pyecharts数据可视化
  7. 洛谷P2822 组合数问题
  8. Django之web框架的本质
  9. 《Java技术》第二次作业计科1501赵健宇
  10. 字符串分割与存入List集合