The ability to end a thread externally allows you to cancel threads that run long requests before they are completed on their own. The methods available for canceling threads vary according to the threads API set that is used.
Some API sets provide well-defined points for the cancelation action to occur or other mechanisms that allow one thread to control when another thread ends. Some API sets also provide a mechanism to run cleanup code before the thread ends or to set the result of the canceled thread to a specific value.
Use thread cancelation carefully. If your API set does not provide well-defined cancelation points or a mechanism for the thread to clean up the application data and locks, you might damage data or cause deadlocks within your application.