Skip to content

Instantly share code, notes, and snippets.

@sumnjc
Created December 10, 2012 04:43
Show Gist options
  • Save sumnjc/4248415 to your computer and use it in GitHub Desktop.
Save sumnjc/4248415 to your computer and use it in GitHub Desktop.
POCO Simple Thread example using threadpool
// 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;
}
@sumnjc
Copy link
Author

sumnjc commented Dec 10, 2012

thread 대신 ThreadPool 을 사용
ThreadPool 은 thread 의 container 로써 Thread 들의 lifetime 을 효율적으로 관리할 수 있도록 해준다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment