Created
August 8, 2012 21:03
-
-
Save MastodonHQ/3298782 to your computer and use it in GitHub Desktop.
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 <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