I am running into problems regarding threading during termination of a c++ console app.
In my main(), I create an object that, itself, launches many threads. The object, called "commGuy" is of type "MultThreadedCommunicator"
. When I eventually delete this object, some of the threads that it has launched have not yet completed. The result is a mess. What I need is a way to wait until all of its threads terminate before I call delete.
The following code illustrates my problem:
Please do not suggest a solution that involves instancing a MultiThreadedCommunicator object directly. For my purposes, it must be referenced only via a pointer obtained by "new".
// instance commGuy
MultiThreadedCommunicator* commGuy = new MultiThreadedCommunicator;
// do a bunch of stuf
// it is now time to terminate the program
// need some code here that waits until commGuy's threads
// terminate before further program execution occurs
// delete commGuy