本文主要介绍线程的模型

一、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. Cow Contest(传递闭包)

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10450   Accepted: 5841 Desc ...

  2. java的小知识点

    1 获取当前路径 System.getProperty("user.dir") System.getProperty()参数大全# java.version            ...

  3. python(pytest)+allure+jenkins 实现接口自动化的思路

    效果图镇楼: 上述各模块作用: python(pytest): 1:用于读测试用例(本次用例写在csv文件中) 2:环境配置相关 3:提取1中的测试数据,组成请求体 4:发送请求 5:获取结果 6:断 ...

  4. 500 Lines or Less: A Template Engine(模板引擎)

    介绍: 多数项目都是包含很多的逻辑处理,只有少部分的文字文本处理.编程语言非常擅长这类项目.但是有一些项目只包含了少量的逻辑处理,大量的文本数据处理.对于这些任务,我们期望有一个工具能够很好的处理这些 ...

  5. Kattis - friday 【数学】

    题意 每一年的第一天 都是星期天 然后 给出 一年的总天数 和 总月数 以及 每个月 的总天数 求出 有多少个星期五 是当月的13号 思路 对于 每个月 只要判断 当月的13号 是不是 星期五 就可以 ...

  6. LRC歌词文件读取代码

    /**************************************************/ /*******************-main文件-******************* ...

  7. spring-boot3

    更多的配置: # =================================================================== # COMMON SPRING BOOT PR ...

  8. C#判断VS是否处于设计模式

    public class CheckDesingModel { public static bool IsDesingMode() { bool ReturnFlag = false; if (Lic ...

  9. Python核心编程课后习题-第六章

    1. 字符串, string模块中是否有一种字符串方法或者函数可以帮我鉴定一下一个字符串是否是另一个大字符串的一部分? str1 = 'abcdefghijklmnopqrstuv' print st ...

  10. GetTickCount的几个案例

    一,获得运行时间: var T1,T2 : double; begin T1 := GetTickCount; //需要做的事情 T2 := GetTickCount; ShowMessage( fl ...