Fix a shutdown race in CPUThreadPoolExecutor::add
Summary: It's not safe to expect that the executor is alive after a task is added to the queue (this task could be holding the last KeepAlive and when finished - it may unblock the executor shutdown). The fix is to hold a KeepAlive if some operation has to be done after adding to the queue. However it's safe to avoid this in a case where executor thread count will never drop below 1 (otherwise not having active threads may result in a deadlock) and we already have the maximum number of threads running. This optimization should help avoid grabbing the KeepAlive on the fast path. The difference from the previous implementation is that we still start with 0 threads. But keep minThreads at at least 1. Differential Revision: D27751098 fbshipit-source-id: 7b992a73b40984376893c1fe2a4a072002f0a12a
Showing
Please register or sign in to comment