官术网_书友最值得收藏!

Thread class

The Thread class is a simple wrapper around an OS-level thread. It takes Worker class instances which inherit from the Runnable class. The official documentation provides a basic example of this as follows:

#include "Poco/Thread.h" 
#include "Poco/Runnable.h"
#include <iostream>

class HelloRunnable: public Poco::Runnable {
virtual void run() {
std::cout << "Hello, world!" << std::endl;
}
};

int main(int argc, char** argv) {
HelloRunnable runnable;
Poco::Thread thread;
thread.start(runnable);
thread.join();
return 0;
}

This preceding code is a very simple "Hello world" example with a worker which only outputs a string via the standard output. The thread instance is allocated on the stack, and kept within the scope of the entry function waiting for the worker to finish using the join() function.

With many of its thread functions, POCO is quite reminiscent of Pthreads, though it does deviate significantly on points such as configuring a thread and other objects. Being a C++ library, it sets properties using class methods rather than filling in a struct and passing it as a parameter.

主站蜘蛛池模板: 宝坻区| 昆明市| 宁安市| 连山| 林口县| 威海市| 屏山县| 西畴县| 青神县| 康定县| 安西县| 司法| 庄河市| 阿尔山市| 茶陵县| 平邑县| 洮南市| 邛崃市| 龙州县| 长乐市| 萝北县| 浮山县| 澎湖县| 会泽县| 五河县| 麦盖提县| 延寿县| 马边| 舞钢市| 合作市| 临沭县| 文山县| 凯里市| 东乌珠穆沁旗| 若羌县| 曲沃县| 全椒县| 新兴县| 长白| 五河县| 新野县|