I am trying to design an active object of sorts that once created, essentially runs in its own thread. What I have done so far is create a class that contains a pthread instance variable, and then in the constructor for that class, it should send the pthread on its way.
Since pthread_create() takes a function parameters, I am passing it a run() function I setup in my class implementation file.
As of now, my run() function is not a part of the class, it is just sitting in the implementation file, but when I tried to compile it, I get an error saying:
"error: ‘run’ was not declared in this scope"
Now I understand why the function run() is out of scope, but would it be correct to just add run() to my active object class as a private function, or would that cause other problems if more than one of these objects existed? Heck, would it cause problems with just one of them instantiated?
Ok here is the code, I just didn't think it mattered much. Here is MyClass.hpp
class MyClass {
private:
pthread_t thread;
ObjectManager *queue;
int error;
// just added this, but the compiler still doesn't like it
void *run(void *arg);
public:
MyClass();
~MyClass();
void start();
}
And here is the implementation, MyClass.cpp:
#include "MyClass.hpp"
void MyClass::start() {
if (queue == NULL)
return;
int status = pthread_create(&thread, NULL, run, (void *) queue);
if (status != 0) {
error = status;
return;
}
}
void *MyClass::run(void *arg) {
bool finished = false;
while (!finished) {
// blah blah blah
}
return NULL;
}