Lv.的博客

随笔分类 -  boost库

摘要:threadpool是基于boost库实现的一个线程池子库,但线程池实现起来不是很复杂。我们从threadpool中又能学到什么东西呢?它是基于boost库实现的,如果大家对boost库有兴趣,看看一个简单的实现还是可以学到点东西的。threadpool基本功能1、任务封装,包括普通任务(task_... 阅读全文
posted @ 2015-05-11 11:38 Avatarx 编辑
摘要:xl_blocking_queue.h?123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354#ifndef SRC_COMMON_BLOCKING_QUE... 阅读全文
posted @ 2015-05-11 11:30 Avatarx 编辑
摘要:建议看这个链接的内容:http://cpp.winxgui.com/cn:mempool-example-boost-pool Pool分配是一种分配内存方法,用于快速分配同样大小的内存块, 尤其是反复分配/释放同样大小的内存块的情况。1. pool 快速分配小块内存,如果pool无法提供小块内存给... 阅读全文
posted @ 2015-05-11 11:26 Avatarx 编辑
摘要:#include #include #include usingnamespaceboost;usingnamespacestd;voidrunChild(constintn){ cout g++ threadgroup.cc -lboost_thread> ./a.out 3如果在freebsd4... 阅读全文
posted @ 2015-05-11 11:15 Avatarx 编辑
该文被密码保护。
posted @ 2015-05-10 08:05 Avatarx 编辑
摘要:namespace{//strand提供串行执行,能够保证线程安全,同时被post或dispatch的方法,不会被并发的执行.//io_service不能保证线程安全boost::asio::io_servicem_service;boost::asio::strandm_strand(m_serv... 阅读全文
posted @ 2015-04-27 23:36 Avatarx 编辑
摘要:This tutorial demonstrates the use of the boost::asio::strand class to synchronise callback handlers in a multithreaded program.The previous four tuto... 阅读全文
posted @ 2015-04-27 23:23 Avatarx 编辑
摘要:In this tutorial we will see how to use a class member function as a callback handler. The program should execute identically to the tutorial program ... 阅读全文
posted @ 2015-04-27 23:20 Avatarx 编辑
摘要:In this tutorial we will modify the program from tutorial Timer.2 so that the timer fires once a second. This will show how to pass additional paramet... 阅读全文
posted @ 2015-04-27 23:19 Avatarx 编辑
摘要:同步Timerasio中提供的timer名为deadline_timer,它提供了超时计时的功能。首先以一个最简单的同步Timer为例来演示如何使用它。#include#includeintmain(){boost::asio::io_serviceio;boost::asio::deadline_... 阅读全文
posted @ 2015-04-27 22:27 Avatarx 编辑
摘要:#include#includeintmain(){boost::asio::io_serviceio;boost::asio::deadline_timertimer(io,boost::posix_time::seconds(3));timer.wait();std::coutexpires_a... 阅读全文
posted @ 2015-04-27 22:05 Avatarx 编辑
摘要:对无锁队列的最初兴趣来自梁斌同志的一个英雄帖:http://coderpk.com/。第一次看到这个题目的时候还不知道CAS,FAA等所谓的“原子操作”,但直觉上感觉,通过对读写操作的性能优化来达到大幅提高队列性能的方法是行不通的,就算读写操作全用汇编来写,也不会和正常的read及write有数量级... 阅读全文
posted @ 2015-04-26 10:25 Avatarx 编辑
摘要:一哥们翻译的boost的无锁队列的官方文档原文地址:http://blog.csdn.net/great3779/article/details/8765103Boost_1_53_0终于迎来了久违的Boost.Lockfree模块,本着学习的心态,将其翻译如下。(原文地址:http://www.b... 阅读全文
posted @ 2015-04-25 15:14 Avatarx 编辑
摘要:转自:http://blog.csdn.net/zhuky/archive/2010/03/10/5364574.aspxBoost.Asio是一个跨平台的网络及底层IO的C++编程库,它使用现代C++手法实现了统一的异步调用模型。头文件#include 名空间using namespace boo... 阅读全文
posted @ 2015-04-25 10:56 Avatarx 编辑
摘要:利用boost来获取当前时间又方便快捷,还不用考虑跨平台的问题。1. 输出YYYYMMDD[cpp]view plaincopy#include#defineBOOST_DATE_TIME_SOURCEstd::stringstrTime=boost::gregorian::to_iso_strin... 阅读全文
posted @ 2015-04-25 09:40 Avatarx 编辑
摘要:前面创建的UDP服务器和客户端,都是同步的方式,也就是说当接收数据时,不能参与别的事情执行的。如果在一个只有界面线程的程序里,又不想创建多线程,导致复杂程度的增加,在这种情况之下,我们还有一个方案可以选择,就是创建一个异步的UDP服务器或客户端,这样既有单线程的简单性,也可以让客户随便操作界面的快速... 阅读全文
posted @ 2015-04-24 11:43 Avatarx 编辑
摘要:Christopher KohlhoffCopyright © 2003-2012 Christopher M. Kohlhoff以Boost1.0的软件授权进行发布(见附带的LICENSE_1_0.txt文件或从http://www.boost.org/LICENSE_1_0.txt)Boost.... 阅读全文
posted @ 2015-04-24 11:39 Avatarx 编辑
摘要:/*Andyisgoingtoholdaconcertwhilethetimeisnotdecided.EricisafansofAndywhodoesn'twanttomissthisconcert.Andydoesn'tknowEric.HowcanEricgetsthenewswhenAndy... 阅读全文
posted @ 2015-04-23 22:49 Avatarx 编辑
摘要:1) 观察者模式定义略,各种设计模式的书上都有定义。2) 观察者模式一般实现观察者模式一般实现,都是“被观察者”保存一个“观察者”的列表,循环这个列表来通知“观察者”。代码,其中使用了boost的智能指针shared_ptr:[cpp]view plaincopy#include#include#i... 阅读全文
posted @ 2015-04-23 22:46 Avatarx 编辑
摘要:http://blog.csdn.net/iamnieo/article/details/29086212008-09-10 12:489202人阅读评论(3)收藏举报thread多线程listlibrary存储io目录(?)[+] C++多线程开发是一个复杂的事情,mfc下提供了CWinThre... 阅读全文
posted @ 2015-04-22 16:07 Avatarx 编辑