Edit: I need to refactor this question, it has too many extraneous components to be clear what my question (which is about C++) is. But anyone who can understand what I am asking please do answer.
I have a class which represents a thread. The threading library I am using, TinyThread++, starts a thread by creating a thread
object, however there is no copy constructor for it. Which makes sense.. What would be the meaning of copying a thread anyway?
Previously I had been initializing my thread object E_thread
this way:
class E_thread {
E_threadRoutine m_routine;
E_thread *m_parent;
thread m_thread;
public:
E_thread(void *(void*),void*,E_thread*);
};
E_thread::E_thread(void *func(void*), void *arg, E_thread* parent):
m_parent(parent), m_routine(func,arg),
m_thread(thread_function_common, &m_routine)
{}
Initializing the thread
ctor in this fashion works, I am sending the pointer of the E_thread
's m_routine
member to the thread as its argument. The purpose of m_routine
is to keep track of thread specific functionality to pass to the thread itself.
However now I want to make a change where I want to allocate m_routine
more carefully. Now m_routine
is a pointer and I will need to set it with
m_routine = new E_threadRoutineTypeX(func,arg,etc);
in the E_thread
ctor body. But this means I can no longer initialize thread
the way I have been. I tried putting
m_thread = thread(thread_function_common,m_routine);
in the body but this copies the thread object which I don't want to do. There's gotta be some syntax for doing this....