Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/155.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 愚蠢的IOThreadPoolExecutor与CPUThreadPoolExecutor_C++_Linux_Folly - Fatal编程技术网

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,因为这是拥有一个工作池的常见用例