关于线程的术语

发布于 2024-07-27 20:10:30 字数 115 浏览 1 评论 0原文

如果线程中的函数要返回,我们如何描述这种行为。

  1. 线程返回。

  2. 线程正在死亡。

“线程已死”是什么意思?

If a function in a thread is going to return, how can we describe this behavior.

  1. The thread returns.

  2. The thread is dying.

What's the meaning of "thread is dead"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

笙痞 2024-08-03 20:10:30

在我的理解中,线程基本上是内核数据结构。 您可以通过系统 API 创建和销毁线程。 如果您只是创建一个线程,启动它执行,并且它耗尽了代码,则内核可能会将其置于非执行状态。 在非托管代码中,您仍然必须释放该资源。

然后是线程池。 在这种情况下,您将线程池要完成的工作排队,平台负责选择线程并执行您的工作。 当工作完成后,线程返回到线程池。 该平台负责创建和销毁线程,以平衡可用线程与工作负载和系统资源。

In my understanding, threads are basically kernel data structures. You can create and destroy threads through the system APIs. If you just create a thread, start it executing, and it runs out of code, the kernel will probably put it into a non-executing state. In unmanaged code you still have to release that resource.

Then there's the thread pool. In that case, you queue up work to be done by the thread pool, and the platform takes care of picking a thread and executing your work. When the work is complete, the thread is returned to the thread pool. The platform takes care of creating and destroying threads to balance the available threads against the workload and the system resources.

浮华 2024-08-03 20:10:30

从 Java 1.3 开始,引入了六状态线程模型。 这包括以下状态:

  1. 准备运行:线程已创建并等待线程调度程序选择运行
  2. 运行:线程正在执行。
  3. 等待:线程在等待某些外部处理(如 I/O)完成时处于阻塞状态。
  4. 睡眠:线程通过.sleep()
  5. 强制睡眠 阻塞On I/O:将移动完成后进入状态1(例如读取一个字节的数据)。 同步:获取锁后将进入状态 1。
  6. 死亡终止):线程已完成工作,无法恢复。

如今“死亡”一词已经很少使用,几乎完全改为“终止”。 这两者是等价的。

As of Java 1.3 the six-state thread model was introduced. This includes the following states:

  1. Ready-to-run: The thread is created and waiting for being picked for running by the thread scheduler
  2. Running: The thread is executing.
  3. Waiting: The thread is in blocked state while waiting for some external processing to finish (like I/O).
  4. Sleeping: The thread is forced to sleep via .sleep()
  5. Blocked: On I/O: Will move into state 1 after finished (e.g. reading a byte of data). On sync: Will move into state 1 after a lock is acquired.
  6. Dead (Terminated): The thread has finished working and cannot be resumed.

The term "Dead" is rarely used today, almost totally changed to "Terminated". These two are equivalent.

高冷爸爸 2024-08-03 20:10:30

大多数线程 API 的工作方式是要求操作系统代表您运行由您提供的特定函数。 当该函数最终返回时(例如通过返回语句或到达其代码末尾),操作系统结束线程。

至于“死”线程——我在线程 API 中没有见过这个术语。

Most thread APIs work by asking the operating system to run a particular function, supplied by you, on your behalf. When this function eventually returns (via for example a return statement or reaching the end of its code) the operationg system ends the thread.

As for "dead" threads - that's not a term I've seen used in thread APIs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文