Boost logo

Boost Users :

Subject: Re: [Boost-users] problems with boost bind and boost thread
From: Marco (marco.schumann_at_[hidden])
Date: 2012-03-22 11:02:46


thanks for your hints (also to Gabriel Redner)!

| I can't realise right now what type trait could be useful for this
| purpose...

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.

class CCycleThread : boost::noncopyable

template<typename T>
CCycleThread(T t) ...

void pause() ...

void resume() ...

void finish() ...


template<typename T>
void execute(T t)

        boost::unique_lock<boost::mutex> lock(m_mut,boost::defer_lock_t());
                //check if the work should be paused or finished

                        //to do: inform user object about pause
                //to do: inform user object about resume
                if (m_finished) break;


                //do the work

And if the user passes a bind object than I have the binding of the binding.

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at