Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1、进程和线程的区别? #1

Open
maxlxq opened this issue Nov 3, 2019 · 0 comments
Open

1、进程和线程的区别? #1

maxlxq opened this issue Nov 3, 2019 · 0 comments

Comments

@maxlxq
Copy link
Owner

maxlxq commented Nov 3, 2019

进程(Process):资源分配的基本单位,程序执行时的一个实例。
线程(Thread):程序执行时的最小单位。

CPU相当于一个工厂,工厂中电力有限,一次只能一个车间工作,这就是单核CPU运行一个进程,一个车间工作时,其他车间都无法工作。
车间中有很多工人,一个进程中也有多个线程。进程中的内存空间是可以共享的,每个线程都可以使用这些共享内存。
不过车间的空间是有大小的,每次只能容纳有限的工人。当部分线程使用100%共享内存时,其他线程必须等其中某个或部分结束。只能拥有单个线程的空间,需要一个互斥锁来防止其他进程同时操作某一块内存区域。当能拥有多个线程的进程执行时,后来的线程需要等待先来的线程执行完毕,这个时候需要一个信号量来控制。

阮一峰关于进程和线程的简单解释

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant