Previous: Using Processor Object Pointers Up: Processor Objects Next: CC++ Computations
delete merger;
When a processor object is deallocated, all member functions currently running are terminated. Deleting a pointer to an object that has already been deleted results in undefined behavior.
Since all member functions which are executing on a processor object are terminated when a processor object is deallocated, we have to be careful. Many threads of control in the computation may be waiting for member functions of the deleted processor object to complete. These threads of control will be suspended forever, perhaps resulting in the suspension of our entire computation.
In our mergesort example, the constructors for Sorter and Merger spawn member functions sort and merge respectively. The semantics of CC++ make no guarantees about when these functions will terminate. However, we know that when the end of the merged output stream is received, these functions have in fact terminated and it is safe to delete all the processor objects.