本文主要介绍线程的模型

一、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. poj2421

    Constructing Roads Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 22048   Accepted: 93 ...

  2. 如何实现模拟器(CHIP-8 interpreter) 绝佳杰作.

    转自 http://www.multigesture.net/articles/how-to-write-an-emulator-chip-8-interpreter/ How to write an ...

  3. 小米4s经常断网

    https://zhidao.baidu.com/question/1387985910554061020.html

  4. zookeeper snowflake 实战

    目录 写在前面 1.1.1. 集群节点的命名服务 1.1.2. snowflake 的ID算法改造 SnowFlake算法的优点: SnowFlake算法的缺点: 写在最后 疯狂创客圈 亿级流量 高并 ...

  5. 教你管理SQL备份与恢复系列(1-20)

    原链接:https://bbs.51cto.com/thread-1147908-1.html 教你备份与恢复数据库,直接下面下文档吧. 教你备份与恢复数据库(1)事务 http://bbs.51ct ...

  6. perl智能匹配

    1.perl中~~为智能匹配,它能够智能地依据符号两側的操作数来确定操作. 如要推断某个元素是否存在于数组中,不使用智能匹配,程序像这样: my $x=2; my @array=(1,2,3); my ...

  7. LeetCode:颜色分类【75】

    LeetCode:颜色分类[75] 题目描述 给定一个包含红色.白色和蓝色,一共 n 个元素的数组,原地对它们进行排序,使得相同颜色的元素相邻,并按照红色.白色.蓝色顺序排列. 此题中,我们使用整数 ...

  8. html ---- web sql 例子

    <!doctype html> <html> <head> <meta charset="utf-8"> <script> ...

  9. python cookbook 迭代器与生成器

    代理迭代 a = [1, 2, 3] for i in iter(a): print(i) for i in a.__iter__(): print(i) 这里的两个方法是一样的,调用iter()其实 ...

  10. 两个小例子彻底明白python decorator

    一:没有什么实际意思,就是单纯的理解decorator.使用装饰器完全可以阻止方法中的代码执行. class json_test(object): def __init__(self, *arg, * ...