// BoostTest.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#define BOOST_MEM_FN_ENABLE_STDCALL
#define BOOST_MEM_FN_ENABLE_FASTCALL
#include <boost/cstdint.hpp>
#include <boost/bind/bind.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/asio/strand.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/detail/thread_group.hpp>
#include <boost/shared_ptr.hpp>
#define STDCALL _stdcall
class IPrint{
public:
virtual void STDCALL print1() = 0;
};
class CPrint : public IPrint
{
public:
CPrint(){}
public:
virtual void STDCALL print1()
{
printf("%s called.\n",__FUNCTION__);
}
void STDCALL print2()
{
printf("%s called.\n",__FUNCTION__);
}
void print_number(int value){
printf("print_number(%d) called.\n", value);
}
};
void OtherTask(boost::asio::io_service & service, boost::asio::io_service::strand &strand);
int _tmain(int argc, _TCHAR* argv[])
{
CPrint printer;
IPrint *pPrinter = &printer;
boost::asio::io_service service;
boost::asio::io_service::work work(service);
boost::asio::io_service::strand strand(service);
boost::thread_group thread_group;
//normal stdcall
thread_group.create_thread(boost::bind(&CPrint::print2, &printer));
//virtual stdcall
thread_group.create_thread(boost::bind(&CPrint::print1, &printer));
//parent class call virtual stdcall fuction
thread_group.create_thread(boost::bind(&IPrint::print1, pPrinter));
//call function with argument
thread_group.create_thread(boost::bind(&CPrint::print_number, &printer, 12));
//normal stdcall
thread_group.create_thread(strand.wrap(boost::bind(&CPrint::print2, &printer)));
//virtual stdcall
thread_group.create_thread(strand.wrap(boost::bind(&CPrint::print1, &printer)));
//parent class call virtual stdcall fuction
thread_group.create_thread(strand.wrap(boost::bind(&IPrint::print1, pPrinter)));
//call function with argument
thread_group.create_thread(strand.wrap(boost::bind(&CPrint::print_number, &printer, 12)));
//boost::thread::sleep(boost::system_time(1000));
service.post(strand.wrap(boost::bind(&CPrint::print_number, &printer, 0)));
service.post(strand.wrap(boost::bind(&CPrint::print_number, &printer, 1)));
service.dispatch(strand.wrap(boost::bind(&CPrint::print_number, &printer, 2)));
service.post(strand.wrap(boost::bind(&CPrint::print_number, &printer, 4)));
service.post(strand.wrap(boost::bind(&CPrint::print_number, &printer, 5)));
boost::thread::sleep(boost::get_system_time()+boost::posix_time::milliseconds(20));
//boost::this_thread::sleep(boost::posix_time::milliseconds(20));
boost::thread *service_thread = thread_group.create_thread(boost::bind(&boost::asio::io_service::run, &service));
thread_group.create_thread(strand.wrap(boost::bind(&OtherTask, boost::bind::ref(service), boost::bind::ref(strand))));
thread_group.join_all();
//service.reset();
//service.run();
return 0;
}
void OtherTask(boost::asio::io_service & service, boost::asio::io_service::strand &strand)
{
service.post(strand.wrap(boost::bind(&CPrint::print_number, &printer, 6)));
service.dispatch(strand.wrap(boost::bind(&CPrint::print_number, &printer, 7)));
service.post(strand.wrap(boost::bind(&CPrint::print_number, &printer, 8)));
}
分享到:
相关推荐
利用Bind_DLZ_MySQL_构建智能DNS.pdf
一份非常好的 SVA 资料,详细介绍怎样写出好的 assertion。资料的最后部分以 sync_fifo 为例子,详细介绍了 assertion 的写法
前端大厂最新面试题-bind_call_apply.docx
linux补丁包bind-9.3.6-20.P1.el5_8.6.x86_64.rpm
被广泛使用的域名服务(DNS)软件
golang websocket源码解读,含有 ListenAndService 主要源码 和 默认路由的源码实现
boost stl一些常用函数的使用训练
js 方法原理解析 apply、bind
Windows_x86_null-free_bindshell_for_Windows_5_0-7_0_all_service_packs
汉化 boost 文档,致力 boost 推广。 如果你对本项目有兴趣,欢迎加入,相关说明请查阅项目论坛: https://groups.google.com/ 到目前为止,各人贡献的译文如下: 贡献者 贡献的译文 alai04 accumulators, any, ...
算是一个消息处理框架吧,用于说函数对象function与bind的基本用法; 比较适合入门boost的function与bind的基本用法
教你怎样在windows_xp上配置DNS服务器
批量绑定autocad外部参照文件,用于大批量地进行cad文件绑定外部参照
利用Internet Protocol Helper API interface结口开发的一个arp保护工具. 开发工具:delphi7
bind_python_container
dns_bind_named_templates
实现了标准库中的function和bind以及智能指针,linux/windows通用。由于公司GCC版本较老,嵌入式的gcc也无法由我来控制,windows上使用的一些类似智能指针,在linux上无法使用,甚是不爽,于是自己手动写了一份,...
proot:chroot,mount --bind和binfmt_misc,没有Linux的特权设置
./bind_exporter [flags] 在Docker容器中运行 使用特定版本提取Docker容器: docker pull prometheuscommunity/bind-exporter:v0.3.0 在Docker容器中运行(作为守护程序),通过localhost与named通信时,请使用--...
主要给大家介绍了关于MongoDB 3.6版本中bind_ip设置的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧