C++ 愚蠢的IOThreadPoolExecutor与CPUThreadPoolExecutor
我试图了解更多关于我正在研究的这个代码库所使用的异步抽象 我正在阅读库中两个异步执行器池的C++ 愚蠢的IOThreadPoolExecutor与CPUThreadPoolExecutor,c++,linux,folly,C++,Linux,Folly,我试图了解更多关于我正在研究的这个代码库所使用的异步抽象 我正在阅读库中两个异步执行器池的Folly文档,IOThreadPoolExecutor用于io绑定任务,以及cputhreadpooleexecutor用于cpu绑定任务() 我正在通读这些描述,但我不明白其中的主要区别。似乎IOThreadPoolExecutor是围绕event\u fd和epoll循环构建的,并且cputhreadpooleexecutor使用队列和信号量 但这并没有告诉我多少好处和取舍。在高级IPThreadPo
Folly
文档,IOThreadPoolExecutor
用于io
绑定任务,以及cputhreadpooleexecutor
用于cpu
绑定任务()
我正在通读这些描述,但我不明白其中的主要区别。似乎IOThreadPoolExecutor
是围绕event\u fd
和epoll
循环构建的,并且cputhreadpooleexecutor
使用队列和信号量
但这并没有告诉我多少好处和取舍。在高级IPThreadPoolExecutor应该只在您需要一个EventBase池时使用。如果需要一个工作池,请使用CPUThreadPoolExecutor。 cputhreadpool执行器 包含一系列优先级队列,这些队列不断被一系列工作人员拾取。每个工作线程在创建后执行threadRun()。ThreadRun()本质上是一个无限循环,它从任务队列中提取一个任务并执行它。如果任务在提取时已过期,则执行expire回调而不是任务本身 IOThreadPoolExecutor 每个IO线程都运行自己的EventBase。IOThreadPoolExecutor不像CPUThreadPoolExecutor那样从任务队列中提取任务,而是将事件注册到下一个IO线程的EventBase。然后,每个IO线程为其EventBase调用loopForEver(),这实际上是调用epoll()来执行异步IO 因此,大多数情况下,您可能应该使用CPUThreadPoolExecutor,因为这是拥有一个工作池的常见用例