Created
December 10, 2012 04:43
-
-
Save sumnjc/4248415 to your computer and use it in GitHub Desktop.
POCO Simple Thread example using threadpool
This file contains hidden or 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
// sample of using POCO's ThreadPool | |
#include "Poco/Runnable.h" | |
#include "Poco/ThreadPool.h" | |
#include <iostream> | |
using namespace std; | |
class Worker:public Poco::Runnable{ | |
public: | |
Worker(int n):_id(n){} | |
virtual void run() { | |
cout << "i'm worker:" << _id << endl; | |
} | |
private: | |
int _id; | |
}; | |
int main(int argc, char **argv) | |
{ | |
Worker work1(1); | |
Worker work2(2); | |
Poco::ThreadPool threadpool; | |
threadpool.start(work1); | |
threadpool.start(work2); | |
threadpool.joinAll(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thread 대신 ThreadPool 을 사용
ThreadPool 은 thread 의 container 로써 Thread 들의 lifetime 을 효율적으로 관리할 수 있도록 해준다.