fix occasional crash in cpu pool
authorJames Sedgwick <jsedgwick@fb.com>
Fri, 19 Sep 2014 10:19:17 +0000 (03:19 -0700)
committerdcsommer <dcsommer@fb.com>
Fri, 19 Sep 2014 22:30:56 +0000 (15:30 -0700)
Summary: need to initialize threadsToStop_ and make it signed so it doesn't underflow in rare races

Test Plan: cpu pool unit tests no longer crash if run a ton of times

Reviewed By: davejwatson@fb.com

Subscribers: fugalh, njormrod

FB internal diff: D1563524

folly/experimental/wangle/concurrent/CPUThreadPoolExecutor.h

index 210fd6733d9d02e92dc01070036cdcb6009ff02c..575e23c60d847cdf7e8dd14c450ac9825cdf2f18 100644 (file)
@@ -53,8 +53,8 @@ class CPUThreadPoolExecutor : public ThreadPoolExecutor {
   void threadRun(ThreadPtr thread) override;
   void stopThreads(size_t n) override;
 
-  std::atomic<size_t> threadsToStop_;
   std::unique_ptr<BlockingQueue<Task>> taskQueue_;
+  std::atomic<ssize_t> threadsToStop_{0};
 };
 
 }} // folly::wangle