Fix a race condition in support library ThreadPool.
authorJustin Lebar <jlebar@google.com>
Wed, 6 Apr 2016 23:46:40 +0000 (23:46 +0000)
committerJustin Lebar <jlebar@google.com>
Wed, 6 Apr 2016 23:46:40 +0000 (23:46 +0000)
commit9e479e4763df7801a7da3209f69dcb4875645552
tree784cf2a65ef7fd5358d64e8ac1d67e78c2e64e5c
parentdd11ee7452beae10875e7690ea5dccda0ee52444
Fix a race condition in support library ThreadPool.

By running TSAN on the ThreadPool unit tests it was discovered that the
threads in the pool can pop tasks off the queue at the same time the
"wait" routine is trying to check if the task queue is empty. This patch
fixes this problem by checking for active threads in the waiter before
checking whether the queue is empty.

Patch by Jason Henline.

Differential Revision: http://reviews.llvm.org/D18811

Reviewers: joker.eph, jlebar
llvm-svn: 265618
llvm/lib/Support/ThreadPool.cpp