是什么
线程是轻量级进程,它是操作系统中CPU利用的基本单位。
引入进程的目的,是为了使多道程序并发执行,以提高资源利用率和系统吞吐量;而引入线程,则是为了减小程序在并发执行时所付出的时空开销,提高操作系统的并发性能。
多线程
- 允许多个线程在同一个进程中。
- 共享同一个进程中的资源,比如代码段,数据段,打开的文件,等等。
- 但是,在进程中的每一个线程拥有私有的线程上下文(包括CPU注册表和其他信息)和私有的栈。
鱼缸与鱼🐟。
优点
RREU
- Responsiveness
Allows other threads to continue responding to the user even if one or several threads is blocked or is performing a lengthy operation.
- Resource sharing
Since threads within the same process share memory and files, they can communicate with each other without invoking the kernel.