user53670
user53670

Reputation:

Terminology about thread

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"?

Upvotes: 0

Views: 123

Answers (3)

Tamás Szelei
Tamás Szelei

Reputation: 23961

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.

Upvotes: 1

anon
anon

Reputation:

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.

Upvotes: 0

Scott Whitlock
Scott Whitlock

Reputation: 13839

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.

Upvotes: 1

Related Questions