On 22/03/12 15:16, Igor R wrote:
I want co call a function or method in a separate thread periodically. Therefore my CCycleThread class starts the execute method as thread and calls the user function object in a loop. The user can pause, resume and finish the thread if he wishes. To separate the worker code from the threading code I build this wrapper around boost thread with pause and resume methods.
<...> Yes, I understand why such a design can be uselful. What I said is that I didn't realise how to separate binder/not-a-binder cases. But after thinking a bit... actually, you can just define 2 function templates in a straight-forward way:
// simple functor/function case template<typename T> CCycleThread(T t) { m_thread.reset(new boost::thread(boost::bind(&CCycleThread::execute<T>, this, t))); }
// binder case template
CCycleThread(boost::_bi::bind_t t) { m_thread.reset(new boost::thread(boost::bind(&CCycleThread::execute , this, boost::protect(t)))); }
Even simpler: just wrap the supplied function/binder in boost::function.
CCycleThread(boost::function