Akagi201
V2EX  ›  问与答

怎么理解 thread pool? 线程池? 一直没有理解?

  •  
  •   Akagi201 · Jun 5, 2014 · 2650 views
    This topic created in 4373 days ago, the information mentioned may be changed or developed.
    在libuv里看到了这句 Each blocking I/O operation is started in a separate thread (or in a thread pool).
    6 replies    2014-06-18 20:48:26 +08:00
    mulog
        1
    mulog  
       Jun 5, 2014   ❤️ 1
    最近看了一下,感觉就是有一组(所谓的pool)预先创建好的线程,来执行某个任务。
    由于线程只创建一次,节省了创建销毁线程的开销。
    有点像一个producer/consumer模式的实现

    菜鸟的个人理解 欢迎拍
    Akagi201
        2
    Akagi201  
    OP
       Jun 5, 2014
    @mulog 恩, 想法类似
    sujin190
        3
    sujin190  
       Jun 5, 2014   ❤️ 1
    线程的创建启动对于一个只是执行较短的时间的任务来说太耗时了,如果你认为非常多但执行时间非常短,比如io什么的,其实线程切换都是一个十分巨大的开销
    isayme
        4
    isayme  
       Jun 5, 2014 via iPad   ❤️ 1
    预先创建一些线程,需要的时候可以快速使用,免去线程创建的开销。
    julyclyde
        5
    julyclyde  
       Jun 18, 2014
    @mulog 那线程的执行体是不是得是个大循环?要不然下一次咋开始呢?
    Akagi201
        6
    Akagi201  
    OP
       Jun 18, 2014
    @julyclyde 线程函数一般都是一个死循环吧, 很少退出, 不知道我理解错你的意思没有
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5631 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 47ms · UTC 06:14 · PVG 14:14 · LAX 23:14 · JFK 02:14
    ♥ Do have faith in what you're doing.