进程和线程

概述

  • 进程:程序的一次运行,操作系统分配内存资源和调度的基本的单位;有独立的内存地址;一个程序至少有一个进程;
  • 线程:最小的执行单元,CPU 调度的单位;由线程ID、程序计数器、寄存器集合和栈组成;一个进程至少有一个线程,多个线程之间共享一段内存,且可并发执行

进程状态

  • 就绪
  • 执行
  • 阻塞

线程间共享变量

  • 互斥锁
  • 信号量

CPU 调度

  • 先到先服务调度(FIFS)
  • 最短作业优先调度(SJF)
  • 优先权调度
  • 轮转法调度(RR)
  • 多级队列调度
  • 多级反馈队列调度

问答

When is a Java thread alive?

According to the Javadoc you mentionned:

A thread is alive if it has been started and has not yet died.

A thread "starts" when its start() method is invoked and "dies" at the end of its run() method, or when stop() (now deprecated) is invoked. So yes, a thread is "alive" when its run() method is still ongoing, but it is also "alive" in the time window between the invocation of start() and the implicit invocation of the run() method by the JVM.

参考

  1. 进程与线程的一个简单解释 - 阮一峰的网络日志
  2. 为什么说线程是CPU调度的基本单位 - huanghantao.github.io
  3. 操作系统之进程的几种状态 - 简书
  4. CPU调度算法总结 - CSDN
写在后面:

1. 子曰:「学而不思则罔,思而不学则殆」。
2. 站点地图
2. 本作品作者为 Lshare,采用知识共享署名 4.0 国际许可协议进行许可。
原文地址:https://www.cnblogs.com/lshare/p/11334225.html