Hey all, Recently I've been designing a Thread class library, I've made a Thread abstract class like the following:
class Thread {
public:
run() { /*start the thread*/ }
kill() { /*stop the thread*/ }
protected:
virtual int doOperation(unsigned int, void *) = 0;
};
Real thread classes would inherit this abstract class and implement doOperation
method in its own logic, something similar to Strategy Pattern.
The problem is that I'm relying on a C back-end library which defines running the thread in the following function:
int startThread(char* name, (int)(*)(unsigned int, void*), int, int, int, void*);
As you can see; the second parameter is a function pointer to thread's loop (main function), and here is the problem; since I use this C-function to start the thread in the run
method, I pass the address of doOperation
to the second parameter, and this cannot be done, because of type mismatch.
I've tried to use reinterpret_cast
to return a pointer, but I ISO-C++ forbids returning a pointer of un-initialized function member.
I don't know how to overcome this conflict, using a static method is the only solution I guess, but it blows up my designing pattern!