I'm trying to write a Thread Pool class in C++ using pthreads on a sun machine.
Basically, the classes construction takes how many worker threads need to be
created, and creates the threads and the queue that manages the list of
of functions needing to be executed. The class also has an add method which
takes a function pointer and function argument as its arguments. It takes
these parameters and populates the queue with this information.
I've written the above, and it all seems to work as an isolated single file
program. The problem I'm encountering is when I try to merge it into the
full blown project. I've put in logging, and it seems that the classes
deconstructor is getting fired as soon as the instance is created. This
forces the threads to shutdown. What's really weird is that subsequent calls
to add seem to successfully fire, but the actual function pointer and argument
are not utilized; that is, they are never executed.
I'm using Sun's 4.1 C++ Compiler with the -mt flag. I'm also linking with
-pthread.
Any ideas what might be wrong? I ran home tonight, and tried the same code
on my Linux machine. I've gotten the same exact results here too, so I'm
pretty sure it's something I'm doing.
Any help will be greatly appreciated.