Contents Up << >>

Background Processing

Key Concepts
Multithreading
Critical sections
Message passing
Re-entrant code

The CTSim graphical shell can optionally perform background processing. CTSim uses threads as tools to achieve this functionality. Using multiple threads, termed multithreading, allows CTSim to:

When background processing option is turned on or when CTSim is running on a SMP computer, and CTSim is directed to perform reconstruction, rasterization, or projections, CTSim will spawn a Background Supervisor thread. This supervisor thread then creates a Supervisor Event Handler (supervisor). The supervisor communicates with the rest of graphical user interface of CTSim by using message passing to avoid issues with re-entrant code.

The supervisor registers itself via message passing with the Background Manager which will display the execution progress in a pop-up window. The supervisor also registers itself with the document being processed. This is done so that if the document is closed, the document can send a message to the supervisor directing the supervisor to cancel the calculation.

After registering with CTSim components, the supervisor creates Worker Threads. These worker threads are the processes that actually perform the calculations. By default, CTSim will create one worker thread for every CPU in the system. As the workers complete unit blocks, they notify the supervisor. The supervisor then sends progress messages to background manager which displays a gauge of the progress.

As the worker threads directly call the supervisor, it is crucial to lock the class data structures with Critical Sections. Critical sections lock areas of code and prevent more than one thread to access a section of code at a time. This is used when maintaining the tables of worker threads in the supervisor.

After the workers have completed their tasks, they notify the supervisor. When all the workers have finished, the supervisor kills the worker threads. The supervisor then collates the work units from the workers and sends a message to CTSim to create a new window to display the finished work.

The supervisor then deregisters itself via messages with the background manager and the document. The background manager removes the progress gauge from its display and resizes its window. Finally, the background supervisor exits and background supervisor thread terminates.

This functionality has been compartmentalized into inheritable C++ classes BackgroundSupervisor, BackgroundWorkerThread, and BackgroundProcessingDocument. These classes serve as base classes for the reconstruction, rasterization, and projection multithreading classes.

Advantages
Disadvantages