Reputation: 23633
There are some member variables and mutexes associated with the object, so it would be easier to use a member function rather than a standalone function.
Upvotes: 0
Views: 198
Reputation: 145194
Provide an operator()
member func.
EDIT: like ...
#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include <iostream>
struct MyThread
{
int x;
MyThread(): x( -1 ) {}
void run() // Name doesn't matter.
{
x = 42;
}
};
int main()
{
namespace b = boost;
using namespace std;
MyThread t;
b::thread_group g;
g.create_thread( b::bind( &MyThread::run, &t ) ) ;
// ... whatever
g.join_all();
cout << t.x << endl;
}
Disclaimer: I'm unfamiliar with Boost threads. And this example added after answer was accepted.
Upvotes: 1