本文主要介绍线程的模型

一、Multi-Process-Parallel vs Multi-Thread-Parallel

多进程的并行:CPU在多个进程之间进行切换,系统给人一种多个进程在并行执行的假象。

多线程的并行:CPU在多个线程之间进行切换,系统给人一种多个线程在并行执行的假象。

进程是资源分配的基本单元,线程是CPU执行的基本单元。

二、进程和线程所独占的资源

前一篇文章已经说了,同一个进程的线程共享进程的资源,在进程中引入线程就是为了让多个执行(线程)共享资源,协调工作完成任务。

但是每个线程有属于自己独享的属性,如上图所示,最为重要的是栈。栈的示意图如下图所示。

线程的栈保存者已经调用但是还没有返回的程序(递归为什么会浪费资源,就是因为有大量的程序调用保存在运行线程的栈中)。栈用于保存执行历史。

假设程序A调用程序B,程序B调用程序C,C调用D,当D在执行时,栈中的数据应该是ABCD,当D执行完毕后,D会出栈,以此类推,A执行返回后栈的数据就会清空。

三、创建新线程

当一个进程启动后,进程至少包含一个线程,该线程可以通过系统调用创建新的线程,创建新线程只需要指定想让该线程执行的方法(Procedure),而无需指定该新线程的地址空间,因为新线程会自动在创建他的线程的地址空间下运行(也就是所属进程的地址空间)。

被创建的线程可以称之为子线程,但是线程之间的hierarchy也不是很重要。

Operating System-Thread(2) Multi-Process-Parallel vs Multi-Thread-Parallel的更多相关文章

  1. [Chapter 3 Process]Practice 3.3 Discuss three major complications that concurrent processing adds to an operating system.

    3.3  Original version of Apple's mobile iOS operating system provied no means of concurrent processi ...

  2. python multi process multi thread

    muti thread: python threading: https://docs.python.org/2/library/threading.html#thread-objects https ...

  3. 如何定位“Operating system error 32(failed to retrieve text for this error. Reason: 15105)”错误中被占用的文件

      之前在这篇"Operating system error 32(failed to retrieve text for this error. Reason: 15105)"博 ...

  4. InnoDB: Operating system error number 87 in a file operation. 错误87的解决方法

    InnoDB: Operating system error number 87 in a file operation. 错误87的解决方法 140628  8:10:48 [Note] Plugi ...

  5. Modern Operating System

    No one can do all things, learn to be good at use what others already did. Most computers have two m ...

  6. The threads in the thread pool will process the requests on the connections concurrently.

    https://docs.oracle.com/javase/tutorial/essential/concurrency/pools.html Most of the executor implem ...

  7. Operating system management of address-translation-related data structures and hardware lookasides

    An approach is provided in a hypervised computer system where a page table request is at an operatin ...

  8. Operating system coordinated thermal management

    A processor's performance state may be adjusted based on processor temperature. On transitions to a ...

  9. Full exploitation of a cluster hardware configuration requires some enhancements to a single-system operating system.

    COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION Operating System Desi ...

  10. osquery An Operating System Instrumentation Framewor

    catalog . Getting Started . install guide for OS X and Linux . Features Overview . Logging . query e ...

随机推荐

  1. phpstorm+xdebug, 实现断点调试: xdebug如何配置

    [XDebug] xdebug.profiler_output_dir="D:\phpStudy\tmp\xdebug" xdebug.trace_output_dir=" ...

  2. ASP连接数据库SQLServer

    Set conn=Server.CreateObject("adodb.connection")Set conn1=Server.CreateObject("adodb. ...

  3. VS2017下编译iconv

    从http://www.gnu.org/software/libiconv/ 下载 libiconv-1.11.1, 这是最后一个支持MSVC编译的版本. 打开 Visual Studio 2017 ...

  4. Android系统移植与调试之------->如何修改Android设备添加重启、飞行模式、静音模式等功能(二)

    今天要说的是为Android设备添加重启.飞行模式.静音模式按钮,客户需求中需要添加这项功能,在长按电源键弹出的菜单中没有这些选项,谨以此文记录自己添加这个功能的过程. 首先找到长按电源键弹出的对话框 ...

  5. linux c编程:文件夹操作

    创建目录: 用mkdir函数创建目录: mkdir(const char *pathname, mode_t mode) 参数mode有下列的组合: S_ISUID 04000 文件的执行时设置用户I ...

  6. 如何在ubuntun中安装intellij idea 2018并破解

    相比eclipse软件,intellij idea的操作更方便.功能更多,几乎集成了所有的java框架. 安装步骤如下: 1 在https://www.jetbrains.com/idea/网站上下载 ...

  7. jquery跟DOM转换

    <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...

  8. RockerMQ connect to<:10009>fail

    producer端发送报错 com.alibaba.rocketmq.client.exception.MQClientException: Send [] times, still failed, ...

  9. Python3 内置函数补充匿名函数

    Python3 匿名函数 定义一个函数与变量的定义非常相似,对于有名函数,必须通过变量名访问 def func(x,y,z=1): return x+y+z print(func(1,2,3)) 匿名 ...

  10. 20145229吴姗珊《Java程序设计》第二周学习总结

    教材学习内容总结 一.类型.变量与运算符 1.类型 整数:可细分为short整数.int整数和long整数.不同长度的整数可储存的整数范围也不同. 字节:byte类型顾名思义.长度就是一字节,需要逐字 ...