日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux下boost的一个扩展线程池-threadpool-的学习

發布時間:2025/3/21 linux 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux下boost的一个扩展线程池-threadpool-的学习 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

轉自:http://www.cnblogs.com/xiaouisme/archive/2012/10/04/2711691.html

安裝boost:

http://www.boost.org/下載boost,我下下來是boost_1_51_0.
boost庫的大部分都可以直接引用頭文件就行了,因為大多數都是頭文件里模板加inline函數構成。但是也有些是需要安裝成二進制lib的,比如thread.(詳見文檔:”Getting Started…”)

$ cd boost_1_51_0 $ sudo ./bootstrap.sh //這條命令類似./configure. 也可以./bootstrap.sh --help看看有哪些命令參數. $ sudo ./b2 install //這樣,boost庫的所有頭文件和需要編譯的lib都安裝到/usr/local/lib 和 /usr/local/include了。(頭文件在boost文件夾里.)
  • 1
  • 2
  • 3

boost擴展工具-線程池(threadpool):
http://threadpool.sourceforge.net/下載threadpool,然后把threadpool里面的boost目錄下的threadpool.hpp和threadpool文件夾拷貝到/usr/local/include/boost/下(如果有權限問題還得cd /usr/local/include/boost && sudo chmod -R 777 *).
使用threadpool需要鏈接boost的兩個共享庫:boost_thread、boost_system(如果是靜態鏈接那就還得動態鏈接pthread庫), 并且include

callback_task.hpp:/** @file callback_task.hpp* @brief add callback task for threadpool.*/#ifndef __callback_task_h__ #define __callback_task_h__#include <boost/function.hpp>namespace boost { namespace threadpool {template<class RetType> class callback_task {typedef boost::function<void (RetType)> CALLBACK;typedef boost::function<RetType ()> FUNCTION;private:CALLBACK m_Callback;FUNCTION m_Function;public:callback_task(FUNCTION f, CALLBACK c):m_Callback(c), m_Function(f){}void operator()(){ m_Callback(m_Function()); } };}} // namespace boost::threadpoll#endif // __callback_task_h__
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
main.cpp:#include <iostream> #include <sstream> #include <boost/threadpool.hpp> #include "callback_task.hpp"using namespace std; using namespace boost::threadpool;void task_normal() {cout << "task_normal()\n"; }void task_with_parameter(int value, string str) {cout << "task_with_parameter(" << value << ", " << str << ")\n"; }bool task_loop() {static int i = 0;cout << "task_loop:" << i <<"\n";return ++i != 5; }int task_return14() { sleep(1);return 14; }void callback(int ret) {cout<< "callback: task_return14() return " << ret << "\n"; }void task_test4ThreadPrivateData() {cout << "task_test4ThreadPrivateData().id:";static map<boost::thread::id, string> s_ThreadPrivateData;boost::thread::id tid = boost::this_thread::get_id();cout << tid << "\n";map<boost::thread::id, string>::iterator it;if((it = s_ThreadPrivateData.find(tid)) == s_ThreadPrivateData.end()){it = s_ThreadPrivateData.insert(make_pair(tid, "hello")).first;}cout << tid << " has private data:" << it->second << "\n"; }void help2SeePoolStatus(pool & tp) {ostringstream os;os << "begin>\n";os << "how many threads in the pool:" << tp.size() << "\n";os << "how many tasks are currently executed:" << tp.active() << "\n";os << "how many tasks are ready and waiting for execution:" << tp.pending() << "\n";os << "<end.";cout<< "\033[1;45;33m"<< os.str() << "\033[0m" << "\n"; }void help2AddAllTask(pool & tp) {tp.schedule( callback_task<int>(&task_return14, callback) );tp.schedule(&task_normal);tp.schedule(boost::bind(task_with_parameter, 4, "number"));tp.schedule( looped_task_func(&task_loop, 0.5*1000) ); tp.schedule(&task_test4ThreadPrivateData); }void testCase0() {cout<< "testCase0()\n" << endl;// Create fifo thread pool container with n threads.pool tp(0);// 0 threads in poolhelp2AddAllTask(tp);help2SeePoolStatus(tp);//Wait until all task are finished.tp.wait(); }void testCase1() {cout<< "testCase1()\n" << endl;pool tp(1);// only one thread in pool.help2AddAllTask(tp);help2SeePoolStatus(tp);tp.size_controller().resize(5);help2SeePoolStatus(tp);tp.wait();help2SeePoolStatus(tp); }void testCase2() {cout<< "testCase2()\n" << endl;pool tp(10);help2AddAllTask(tp);for(int i = 0; i != 4; i++, help2SeePoolStatus(tp), sleep(.5));tp.wait(); }int main(int argc,char *argv[]) {testCase1();return(0); }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
CMakeLists.txt:cmake_minimum_required(VERSION 2.8)project(test)SET(CMAKE_C_COMPILER "g++") SET(SRC_LIST main.cpp)ADD_EXECUTABLE(${PROJECT_NAME} ${SRC_LIST}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} boost_thread boost_system)

總結

以上是生活随笔為你收集整理的linux下boost的一个扩展线程池-threadpool-的学习的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 久久久久久国产精品三级玉女聊斋 | 日本一区二区三区视频在线播放 | 精品一区二区av | 女人被男人躁得好爽免费视频 | 成人尤物| 亚洲精品在线免费 | 中文字幕乱妇无码av在线 | 国产成人97精品免费看片 | www狠狠操 | 免费毛片在线 | 国产精品卡一卡二 | 国产av一区二区三区最新精品 | 国产婷婷在线观看 | 精品国产乱码久久久久久鸭王1 | 521av在线 | 青青操狠狠干 | 贵族女沦为官妓h呻吟 | 玖草在线观看 | 日本免费在线视频观看 | 日本一级吃奶淫片免费 | 成人h在线 | 色悠悠av| 日韩在线精品视频一区二区涩爱 | 五十路六十路七十路熟婆 | 国产免费一区二区三区在线播放 | 日韩黄视频| 亚洲精品www久久久久久 | 91深夜视频 | 视频福利在线观看 | 男生插女生的视频 | 欧美日韩综合一区二区三区 | 悠悠色综合 | 91叉叉叉| 一级h片| 欧美成人综合视频 | 91av色| 亚洲一级二级 | 男人和女人日批 | 精品久久久在线观看 | 亚洲成人一二区 | 美女黄18以下禁止观看 | 特大黑人巨人吊xxxx | 日本亲与子乱ay中文 | 男人的天堂av网 | 毛片在线看网站 | 91麻豆影视| 亚洲福利影院 | 亚洲视频在线免费观看 | 天堂av最新网址 | 交专区videossex | www.久久婷婷 | 亚洲一区二区三区加勒比 | 91最新地址永久入口 | 年下总裁被打光屁股sp | 这里只有精品视频 | 激情网色| 亚洲综合婷婷 | 久久精品中文 | 亚洲国产成 | 午夜视频1000 | 在线色综合 | 国产精品无码午夜福利 | 欧美a在线观看 | 操她视频在线观看 | 天堂网2018 | 久久成人福利视频 | 香蕉网在线播放 | 亚洲专区一区 | 久久综合影院 | 一级成人免费视频 | 嫩草一区二区三区 | 色哟哟精品观看 | 精精国产 | 国产一区不卡视频 | 人人舔人人干 | 一区二区三区四区五区视频 | 四虎成人在线视频 | 亚洲精品成人区在线观看 | 国产精品传媒一区二区 | 国产精品久久久久一区二区三区 | 欧美成人一区在线观看 | 欧美激情精品久久久久久 | 狠狠做深爱婷婷久久综合一区 | av一级免费 | 色天堂在线视频 | 国内精品亚洲 | 在线观看国产视频 | 免费在线观看日韩av | 美乳人妻一区二区三区 | 亚洲风情亚aⅴ在线发布 | 国产精品手机视频 | 国产午夜毛片 | 一区二区在线视频观看 | 欧美激情一区二区三区在线 | 午夜寂寞视频 | 蜜桃视频在线观看一区二区 | 实拍女处破www免费看 | 黄色成人在线免费观看 | 精品久久一区二区三区 |