Skip to content

Instantly share code, notes, and snippets.

@digitalist
Forked from sumnjc/thread1.cpp
Last active November 14, 2024 04:37
Show Gist options
  • Save digitalist/dc2347a16ad417d05d602f2355fe870f to your computer and use it in GitHub Desktop.
Save digitalist/dc2347a16ad417d05d602f2355fe870f to your computer and use it in GitHub Desktop.
POCO Simple Thread example
// 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;
}
@digitalist
Copy link
Author

CMakeLists.txt

set(INSTALL_DIR /home/user/temp/testpoco)
# build poco:
#cmake -DENABLE_CRYPTO=OFF -DENABLE_NETSSL=OFF -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} .. && make clean && make

# build pocothread.cpp
# cmake .. && gmake clean && gmake

cmake_minimum_required(VERSION 3.9)
include_directories(${INSTALL_DIR}/include)
link_directories(${INSTALL_DIR}/lib)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -stdlib=libc++")

add_executable(poctest pocothread.cpp)
target_link_libraries(poctest PocoFoundation)

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