leohotfn
V2EX  ›  C

小巧的 C++线程池

  •  
  •   leohotfn · May 23, 2017 · 3548 views
    This topic created in 3454 days ago, the information mentioned may be changed or developed.

    https://github.com/leohotfn/Reuzel 欢迎来 star 和 fork!

    12 replies  •  2017-05-24 15:41:09 +08:00
    chchwy
    chchwy
    May 23, 2017
    1
    只有 Linux 阿...
    000wangxinyu000
    000wangxinyu000
    May 23, 2017
    2
    将 task 封装成抽象类,每次 addTask 传入子类对象。子类中可以保存一些与任务相关的状态变量。
    000wangxinyu000
    000wangxinyu000
    May 23, 2017
    3
    将与系统相关的 api 都封装起来,例如锁类和线程类。在不同的平台有不同的实现。
    000wangxinyu000
    000wangxinyu000
    May 23, 2017
    4
    然后加入一些日志以及性能监控之类的功能,就越来越复杂了
    AngelCriss
    AngelCriss
    May 23, 2017
    5
    https://github.com/abbycin/tools/tree/master/threadpool
    我也贴一个,给点意见啊。。
    luoqeng
    luoqeng
    May 23, 2017
    6
    std::thread
    zmj1316
    zmj1316
    May 23, 2017
    7
    pthread ...
    araraloren
    araraloren
    May 24, 2017
    8
    linux only 也叫 feature 吗 - - ?
    gesse
    gesse
    May 24, 2017
    9


    半个月不到的个人小众项目, 一下刷到 111 stars,v2ex 小伙伴太给力了, 不过感觉是不是有碍公平? 扰乱平台?
    sgissb1
    sgissb1
    May 24, 2017❤️1
    10
    @gesse 关键估计哥们看了 boost 里面的代码,虽然代码量不大,但确实能看到部分 boost 写法的影子。一个简易的线程池,如果是出于学习和研究的目的,还是值得鼓励。

    但如果出于其他目的就拉倒了。

    这年头号称会用、懂线程的人太多了,但线程粒度也不算大,要玩转也不容易。看看代码就可以决定要不要 satr、fork 了。
    popstk
    popstk
    May 24, 2017
    11
    https://github.com/log4cplus/ThreadPool 这个充分使用 C++11 语法,更加轻量仅一个头文件。
    timothyqiu
    timothyqiu
    May 24, 2017
    12
    既然已经用了 C++11 了,为什么还要自己造轮子不用 std::thread 系列……
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1763 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 05:47 · PVG 13:47 · LAX 21:47 · JFK 00:47
    ♥ Do have faith in what you're doing.