Created
December 10, 2012 03:25
-
-
Save sumnjc/4248200 to your computer and use it in GitHub Desktop.
POCO Simple Thread example
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
// sample of using POCO's Thread | |
#include "Poco/Runnable.h" | |
#include "Poco/Thread.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::Thread thread1; | |
Poco::Thread thread2; | |
thread1.start(work1); | |
thread2.start(work2); | |
thread1.join(); | |
thread2.join(); | |
return 0; | |
} |
Author
sumnjc
commented
Dec 10, 2012
- PocoFoundation에 linking
- Runnable 클래스에서 상속받아 Working Class 를 작성
- Working Class 에서 run() 메소드를 재작성
- Thread 객체 및 Working 객체 생성
- Thread 객체에 Working 객체를 인자로 .start() 호출
- 적절한 곳에서 join() 메소드를 호출하여 각각의 Thread 의 종료를 대기
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment