Thread pool task manager shut-down

For an overview of the thread pool task manager please see: Thread pool task manager: overview.

Thread pool task manager shut-down sequence

The thread pool task manager is shut-down by calling Dispose() as depicted in the following sequence diagram:

mtf-runtime-taskman-dispose.png

Shutting down the thread pool task manager involves safely closing down its threads. There are two modes of shutdown:
  • Graceful exit - wait for currently executing tasks to finish and then exit
  • Forced exit - abort currently executing tasks and exit immediately

The latter approach is only intended to be used where the application state is either not used or is reinitialized after exit as it uses a Thread.Abort() call to terminate the threads, which leaves the data that they were working on in an unknown state.

To shut down the thread pool task manager, the following steps are executed:
  1. If the OnPreShutdown event is defined then invoke it
  2. For each thread from the processing and GUI pools, call Terminate() to tell them to stop
  3. If not using forced exit, send an empty task into every worker thread from each pool to unblock them and allow them to exit gracefully

The ThreadWorker's Terminate() method sets its IsAlive flag to false, which allows the thread's main loop to exit. In addition, if using forced exit, Terminate() calls Thread.Abort() on the ThreadWorker's thread causing the thread to terminate immediately.

Last edited Aug 30, 2012 at 9:10 AM by jaorme, version 5

Comments

No comments yet.