美文网首页
【The Java™ Tutorials】【Concurrenc

【The Java™ Tutorials】【Concurrenc

作者: Ppian | 来源:发表于2018-04-19 14:16 被阅读0次

进程 vs. 线程

Process
A process has a self-contained execution environment. A process generally has a complete, private set of basic run-time resources; in particular, each process has its own memory space.

To facilitate communication between processes, most operating systems support Inter Process Communication (IPC) resources, such as pipes and sockets. IPC is used not just for communication between processes on the same system, but processes on different systems.

Thread
Threads are sometimes called lightweight processes. Both processes and threads provide an execution environment, but creating a new thread requires fewer resources than creating a new process.

Threads exist within a process — every process has at least one. Threads share the process's resources, including memory and open files. This makes for efficient, but potentially problematic, communication.

进程是cpu资源分配的最小单位,线程是cpu调度的最小单位。

进程有独立的地址空间,线程是属于进程的,线程运行在进程空间内。同一进程所产生的线程共享同一内存空间,当进程退出时该进程所产生的线程都会被强制退出并清除。线程可与属于同一进程的其它线程共享进程所拥有的全部资源,但是其本身基本上不拥有系统资源,只拥有一点在运行中必不可少的信息(如程序计数器、一组寄存器和栈)。所以线程比进程更轻量,在进行上下文切换时,线程的开销更小。同时,同一进程的线程共享进程的资源(内存空间,打开的文件等),所以线程间的通信更加简单。

阅读链接:
阮一峰:进程与线程的一个简单解释
知乎:线程和进程的区别是什么?

相关文章

网友评论

      本文标题:【The Java™ Tutorials】【Concurrenc

      本文链接:https://www.haomeiwen.com/subject/sgzbcftx.html