进程,线程,协程,异步IO知识点
进程: qq 要以一个整体的形式暴露给操作系统管理,里面包含对各种资源的调用,内存的管理,网络接口的调用等。。。
对各种资源管理的集合 就可以成为 进程
线程: 是操作系统最小的调度单位, 是一串指令的集合
进程 要操作cpu , 必须要先创建一个线程 ,
all the threads in a process have the same view of the memory
所有在同一个进程里的线程是共享同一块内存空间的
A thread线程 is an execution执行 context上下文, which is all the information a CPU needs to execute a stream of instructions.
线程就是cpu执行时所需要的
Suppose you're reading a book, and you want to take a break right now, but you want to be able to come back and resume reading from the exact point where you stopped. One way to achieve that is by jotting down the page number, line number, and word number. So your execution context for reading a book is these 3 numbers.
假设
If you have a roommate, and she's using the same technique, she can take the book while you're not using it, and resume reading from where she stopped. Then you can take it back, and resume it from where you were.
Threads work in the same way. A CPU is giving you the 幻觉illusion that it's doing multiple多 computations运算 at the same time. It does that by spending花费 a bit点 of time on each computation运算. It can do that because it has an execution context for each computation. Just like you can share a book with your friend, many tasks can share a CPU.
On a more technical level, an execution context (therefore a thread) consists组合 of the values of the CPU's registers 寄存器.
Last: threads are different from 进程processes. A thread is a context of execution, while a process is a bunch一簇,一堆 of resources资源 associated相关的 with a computation. A process can have one or many threads.
Clarification: the resources associated with a process include memory pages (all the threads in a process have the same view of the memory), file descriptors (e.g., open sockets), and security credentials (e.g., the ID of the user who started the process).
什么是进程(process)?
An executing instance of a program is called a process.
Each process provides the resources needed to execute a program.
A process has a virtual虚拟 address space, executable code,
open handles to system objects, a security context,
a unique唯一的 process进程标识符,pid identifier, environment variables,
a priority 优先级类class, minimum and maximum working set sizes,
and at least至少 one thread线程 of execution.
Each process is started with a single thread,
often called the primary主 thread, but can create additional额外的
threads from any of its threads.
进程与线程的区别?
Threads share the address space of the process that created it; processes have their own address space.
线程共享内存空间,进程的内存是独立的
Threads have direct access to the data segment of its process; processes have their own copy of the data segment of the parent process.
Threads can directly communicate with other threads of its process; processes must use interprocess communication to communicate with sibling processes.
同一个进程的线程之间可以直接交流,两个进程想通信,必须通过一个中间代理来实现
New threads are easily created; new processes require duplication of the parent process.
创建新线程很简单, 创建新进程需要对其父进程进行一次克隆
Threads can exercise considerable control over threads of the same process; processes can only exercise control over child processes.
一个线程可以控制和操作同一进程里的其他线程,但是进程只能操作子进程
线程 内存共享
线程同时修改同一份数据时必须加锁,mutex互斥锁
递归锁
def run(n):
print('run thread...')
for i in range(10):
t = threading.Thread(target=run, args=(n,))
t.setDaemon(True)
t.start()
print 'master is done....'
守护线程(slave) 服务与非守护线程(master)
进程 至少包含一个线程
queue
解耦,使程序直接实现松耦合,
提高处理效率 ,
FIFO = first in first out
LIFO = last in first out
io 操作不占用cpu
计算占用cpu , 1+1
python多线程 不适合cpu密集操作型的任务,适合io操作密集型的任务
multiprocess
Queue \ Pipe 只是实现进程间数据的传递
Manager 实现了进程间数据的共享,即多个进程可以修改同一份数据
IO 多路复用
进程,线程,协程,异步IO知识点的更多相关文章
- 并发 并行 进程 线程 协程 异步I/O python async
一些草率不精确的观点: 并发: 一起发生,occurence: sth that happens. 并行: 同时处理. parallel lines: 平行线.thread.join()之前是啥?落霞 ...
- 线程、进程、协程 异步io
https://www.cnblogs.com/wupeiqi/articles/6229292.html
- 多道技术 进程 线程 协程 GIL锁 同步异步 高并发的解决方案 生产者消费者模型
本文基本内容 多道技术 进程 线程 协程 并发 多线程 多进程 线程池 进程池 GIL锁 互斥锁 网络IO 同步 异步等 实现高并发的几种方式 协程:单线程实现并发 一 多道技术 产生背景 所有程序串 ...
- Python并发编程系列之常用概念剖析:并行 串行 并发 同步 异步 阻塞 非阻塞 进程 线程 协程
1 引言 并发.并行.串行.同步.异步.阻塞.非阻塞.进程.线程.协程是并发编程中的常见概念,相似却也有却不尽相同,令人头痛,这一篇博文中我们来区分一下这些概念. 2 并发与并行 在解释并发与并行之前 ...
- 进程&线程&协程
进程 一.基本概念 进程是系统资源分配的最小单位, 程序隔离的边界系统由一个个进程(程序)组成.一般情况下,包括文本区域(text region).数据区域(data region)和堆栈(stac ...
- Python 进程线程协程 GIL 闭包 与高阶函数(五)
Python 进程线程协程 GIL 闭包 与高阶函数(五) 1 GIL线程全局锁 线程全局锁(Global Interpreter Lock),即Python为了保证线程安全而采取的独立线程运行的 ...
- python自动化开发学习 进程, 线程, 协程
python自动化开发学习 进程, 线程, 协程 前言 在过去单核CPU也可以执行多任务,操作系统轮流让各个任务交替执行,任务1执行0.01秒,切换任务2,任务2执行0.01秒,在切换到任务3,这 ...
- python 多协程异步IO爬取网页加速3倍。
from urllib import request import gevent,time from gevent import monkey#该模块让当前程序所有io操作单独标记,进行异步操作. m ...
- Python之路,Day9 - 线程、进程、协程和IO多路复用
参考博客: 线程.进程.协程: http://www.cnblogs.com/wupeiqi/articles/5040827.html http://www.cnblogs.com/alex3714 ...
- python的进程/线程/协程
1.python的多线程 多线程就是在同一时刻执行多个不同的程序,然而python中的多线程并不能真正的实现并行,这是由于cpython解释器中的GIL(全局解释器锁)捣的鬼,这把锁保证了同一时刻只有 ...
随机推荐
- Final Cut Pro X for Mac(FCPX专业视频剪辑工具)实用技巧篇!
Final Cut Pro X for Mac是一款非常强大的专业视频剪辑工具,全球很多人都在用!现在小编给大家带来一些关于Final Cut Pro X for Mac的使用技巧,希望对大家以后的应 ...
- ECMAScript 6 之 let 和 const 命令
1.let基本用法 1.1.声明变量 let声明的变量只在它所在的代码块有效. 1.2.不存在变量提升 var命令会发生”变量提升“现象,即变量可以在声明之前使用,值为undefined: let命令 ...
- 3dmax 笔记本电脑
一般来说,苹果MacBook系列适合运行3ds Max. 3ds Max是一款大型图像处理软件,对电脑硬件要求高.在所有MacBook系列中,配备Retina屏幕的MacBook Pro 15寸是最佳 ...
- javascript 数据类型 -- 检测
一.前言 在上一篇博文中 Javascript 数据类型 -- 分类 中,我们梳理了 javascript 的基本类型和引用类型,并提到了一些冷知识.大概的知识框架如下: 这篇博文就讲一下在写代码的过 ...
- 在虚拟机中安装Centos系统
1.首先下载VMware 2.然后可以去http://mirrors.aliyun.com下载映像ISO 3.打开VM,点击创建新的虚拟机 4.选择典型模式 5.稍后安装操作系统 6.选择你所要安装的 ...
- Scanner,Random,匿名对象-------------------java基础学习第七天
1.API 2.Scanner 功能:通过键盘输入数据到程序中. 引用类型的一般使用步骤: 导包 Import 包路径.类名称 只有java.lang 包写的类不需要导包,其他都需要 2.创建 类名称 ...
- Java_流程控制
介绍: java的流程控制结构有三种:顺序.选择.循环 顺序结构,就是从头到尾依次执行每条语句的操作. 选择结构,也称条件控制,是指根据表达式的值有选择的执行. 循环结构,也称回 ...
- G102040I
傻逼题.我从来没见过eps这样的... 打破了我对计算几何美好的幻想. eps=1e-6=>wa3 eps=1e-8->wa2 eps 1e-4->AC 真的自闭,真的猜不到ep ...
- 02 . 处理axios的三个问题 :设置基路径/axios挂载到vue原型/请求时自动携带token
//使用API时必须在请求头中使用 Authorization 字段提供 token 令牌 import axios from 'axios' // 处理axios的三个问题 // 处理一:基路径 a ...
- 关于js的页面高度和滚动条高度还有元素高度
window.innerHeight 这是浏览器里面内容的高度,直接就是值,不需要其它操作; window.pageYOffset 这是滚动条到浏览器顶端的距离; $(元素).offset(). ...