关于线程的术语
如果线程中的函数要返回,我们如何描述这种行为。
线程返回。
线程正在死亡。
“线程已死”是什么意思?
If a function in a thread is going to return, how can we describe this behavior.
The thread returns.
The thread is dying.
What's the meaning of "thread is dead"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在我的理解中,线程基本上是内核数据结构。 您可以通过系统 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.
从 Java 1.3 开始,引入了六状态线程模型。 这包括以下状态:
.sleep()
如今“死亡”一词已经很少使用,几乎完全改为“终止”。 这两者是等价的。
As of Java 1.3 the six-state thread model was introduced. This includes the following states:
.sleep()
The term "Dead" is rarely used today, almost totally changed to "Terminated". These two are equivalent.
大多数线程 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.