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. Differential Revision: D27584518 fbshipit-source-id: e1242e3f4c40cee4f7e0c6dfca39abe6d17415f1
Showing
Please register or sign in to comment