Skip to content

Instantly share code, notes, and snippets.

@MastodonHQ
Created August 8, 2012 21:03
Show Gist options
  • Save MastodonHQ/3298782 to your computer and use it in GitHub Desktop.
Save MastodonHQ/3298782 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <boost/thread.hpp>
using namespace std;
using namespace boost;
class Worker
{
public:
Worker(string name, string ID)
: wname(name), wid(ID)
{
cout<<"Worker ["<<wname<<"] ID ["<<wid<<"] Created"<<endl;
}
void start();
void join();
void routine();
private:
boost::thread wthread;
string wname;
string wid;
};
void Worker::start(){
wthread = boost::thread(this->routine);
}
void Worker::join(){
wthread.join();
}
void Worker::routine(){
cout<<"["<<wname<<"]["<<wid<<"]: Start"<<endl;
cout<<"["<<wname<<"]["<<wid<<"]: Done"<<endl;
}
int main(int argc, char ** argv){
cout<<"Main: Start"<<endl;
cout<<"Main: Creating Worker"<<endl;
Worker azriel("azriel","001");
azriel.start();
azriel.join();
cout<<"Main: Done"<<endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment