Created
August 8, 2012 03:47
-
-
Save MastodonHQ/3291875 to your computer and use it in GitHub Desktop.
A Functor that takes a string and a function pointer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <boost/thread.hpp> | |
#include <iostream> | |
#include <string> | |
using namespace std; | |
using namespace boost; | |
class worker | |
{ | |
public: | |
worker(string wname) | |
: m_wname(wname) | |
{ | |
} | |
void operator()(){ | |
cout<<"Worker[ "<< m_wname <<" ]: "; | |
} | |
void start(string callstring); | |
void join(); | |
void (*w_callback)(string callstring); | |
private: | |
boost::thread m_thread; | |
string m_wname; | |
}; | |
void worker::start(string callstring){ | |
m_thread = boost::thread(&worker::w_callback,this,callstring); | |
} | |
void worker::join(){ | |
m_thread.join(); | |
} | |
void callback(string Callback){ | |
cout <<"Callback: " << Callback << endl; | |
} | |
int main(int argc, char ** argv){ | |
cout << "Main: Start" << endl; | |
worker workme("workme"); | |
workme.w_callback = &callback; | |
workme.start("CallBack CallString"); | |
workme.join(); | |
cout << "Main: Waiting on thread" << endl; | |
cout << "Main: Returned to Main" << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment