struct my_functor
{
void operator()()
{
std::cout << "Here I am, doing some work in " << __PRETTY_FUNCTION__
<< " on thread " << boost::this_thread::get_id() << std::endl;
}
};
struct my_class
{
void some_function(int b)
{
std::cout << "Here I am, doing some work in " << __PRETTY_FUNCTION__
<< " on thread " << boost::this_thread::get_id()
<< " and my input is " << b << std::endl;
}
};
void free_function_1()
{
std::cout << "Here I am, doing some work in " << __PRETTY_FUNCTION__
<< " on thread " << boost::this_thread::get_id() << std::endl;
}
void free_function_2(char c)
{
std::cout << "Here I am, doing some work in " << __PRETTY_FUNCTION__
<< " on thread " << boost::this_thread::get_id()
<< " and my input is " << c << std::endl;
}
int main()
{
std::cout << __PRETTY_FUNCTION__ << " thread id is: " << boost::this_thread::get_id() << std::endl;
job_queue queue;
boost::thread another_thread = create_thread(&queue);
my_functor mf;
my_class mc;
queue.post(mf); // post a function object (functor) to the queue
queue.post(boost::bind(&my_class::some_function, mc, 7)); // bind creates a functor - binding member function to class instance, and an argument
queue.post(boost::bind(&free_function_1)); // bind creates a functor from a free function
queue.post(boost::bind(&free_function_2, 'z')); // bind creates a functor from a free function and binds the argument
// stop the queue and let it complete all jobs
queue.stop(false);
another_thread.join();
return 0;
}
//-----------------------------------------------------------------------