/**
* Create only by new operator, delete by owner
* joinable m_thread
*/
class LaThread {
private:
boost::thread* m_thread;
static static_run(LaThread* This) {
This->run();
}
protected:
virtual void run() = 0;
public:
LaThread() : m_thread(NULL) {}
/**
* Requires: threat ended
*/
virtual ~LaThread(){
if( m_thread != NULL )
delete m_thread;
}
public:
void start() {
if( m_thread != NULL ) {
throw std::exception(_T("m_thread != NULL"));
}
m_thread = new boost::thread( boost::bind(static_run, this) );
}
void join() {
if( m_thread == NULL ) {
throw std::exception(_T("m_thread == NULL"));
}
m_thread->join();
}
};
class TestThread : public LaThread {
private:
int arg;
public:
TestThread( int arg ) {
this->arg = arg;
}
public:
virtual void run() {
_RPT3(_CRT_WARN, "[%d]\t[%s]\t[%s]\n", ::GetCurrentThreadId(), _T("Hi I'm new thread!"), __FUNCTION__);
}
};
主要看点是:
new boost::thread( boost::bind(static_run, this) );
boost::bind使可以使 static_run(LaThread* This) 变成满足 boost::thread ( boost::function0 fuc )要求的函数。
C++ ISO 1998 的确并不是一个STL Container那么简单啊。还有boost::mem_fn呢。
解决这类别扭问题的方法的:
google: Boost Thread parameter
回复者(可能是Thread文档的开发者),说这样的说明将会加入到下个版本的文档中。
分享到:
相关推荐
boost.thread.1.3.5中文翻译
详细讲述了boost::thread的用法
boost::asio::serial下6个工程演示多种串口读取写入方式方法,包含simple,with_timeout,async,callback,qt_integration,stream 等多个工程演示多种方式读取,写入串口,char,string ,buffer[]等多种数据格式。
boost::function0可以简单看为:一个无返回(返回void),无参数的函数。这里的函数也可以是类重载operator()构成的函数;该构造函数传入的是函数对象而并非是函数指针,这样一个具有一般函数特性的类也能作为参数...
THE BOOST C++ LIBRARIES是一份自己编译的chm格式文档,描述了如何使用boost类库,目录如下: Front page Chapter 1: Introduction 1.1 C++ and Boost 1.2 Development Process 1.3 Installation 1.4 Overview ...
Windows安装boost库 下载链接:https://www.boost.org/ 学习链接:https://theboostcpplibraries.com/ 1,下载解压,我的目录“C:\Program Files (x86)\Microsoft Visual Studio\2017” 2,以管理员身份运行“适用...
boost-thread.pdf boost_1_41_文档_中文版.chm boost_1_43_0_doc_en.chm Boost库学习指南.pdf Boost教程.pdf boost概览.pdf 侯捷_-_Boost_技术与应用.pdf 智能指针的标准之争 Boost_vs_Loki.pdf
Boost库文件采用的.hpp的后缀,而不是分成两个文件,也就是”.h+.cpp”,之所以这样做是有理由的,首先就是与普通的C/...Boost中90%的库不需要编译,但像data_time、regex、test、thread等库必须编译成静态库或者动态库
好例程,vs安装好库后,加好工程文件就可以跑了。ubuntu下同样道理。
Boost库是一个经过千锤百炼、可移植、提供源代码的C++库,,作为标准库的后备,是C++标准化进程的发动机之一。 Boost库由C++标准委员会库工作组成员发起,其中有些内容有望成为下一代C++标准库内容。在C++社区中影响...
#include <boost/thread.hpp> using namespace std; void hello() { for( int i=0; i;i++ ){ cout , wudimei.com!"<< " thread id: "<< boost::this_thread::get_id() ; } } int main() { boost::thread ...
Boost库是一个经过千锤百炼、可移植、提供源代码的C++库,作为标准库的后备,是C++标准化进程的发动机之一。 Boost库由C++标准委员会库工作组成员发起,其中有些内容有望成为下一代C++标准库内容。 Boost中比较有...
C++ Boost Thread 编程指南 0分上船
BOOST 线程 池库源码
boost-thread-1.41.0-11.el6_1.2.i686.rpm是centos工具包。
一个 vs 使用 boost thread dll 的demo,IDE 是 vs15。其中包含所需要头文件和dll,可放心下载,有使用问题可发email到157369414@qq.com
《Linux多线程服务端编程:使用muduo C++网络库》主要讲述采用现代C++在x86-64 Linux上编写多线程TCP网络服务程序的主流常规技术,重点讲解一种适应性较强的多线程服务器的编程模型,即one loop per thread。...
VC 6.0++下已编译好的boost之中Thread类的lib,方便大家使用,减少编译麻烦。包含(lib和hpp)
CUJ预言它将衍生自Boost线程库,现在就由Bill带领我们探索一下Boost线程库。 就在几年前,用多线程执行程序还是一件非比寻常的事。然而今天互联网应用服务程序普遍使用多线程来提高与多客户链接时的效率;为了达到...