views:

60

answers:

4

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

+1  A: 

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.

Scott Whitlock
A: 

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.

anon
A: 

I'd use "The thread is terminating" instead. Return sounds very programming language specific.

JG
+1  A: 

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.

Tamás Szelei