From 29d4c417a8a05c743d3a89310ebc1cbb2dfa0cfd Mon Sep 17 00:00:00 2001 From: Dario Russi Date: Mon, 13 Jan 2014 17:00:57 -0800 Subject: [PATCH] fix AtomicHashMap race condition Summary: AHM::find checks that the returned SimpleRetT index is >= numMapsAllocated_ but that value may have changed and find pick the first element in the next sub map. Use success instead. @override-unit-failures Test Plan: unit tests Reviewed By: delong.j@fb.com FB internal diff: D1126684 --- folly/AtomicHashMap-inl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/folly/AtomicHashMap-inl.h b/folly/AtomicHashMap-inl.h index a2f497af..9d8d84a5 100644 --- a/folly/AtomicHashMap-inl.h +++ b/folly/AtomicHashMap-inl.h @@ -155,7 +155,7 @@ typename AtomicHashMap::iterator AtomicHashMap:: find(KeyT k) { SimpleRetT ret = findInternal(k); - if (ret.i >= numMapsAllocated_.load(std::memory_order_acquire)) { + if (!ret.success) { return end(); } SubMap* subMap = subMaps_[ret.i].load(std::memory_order_relaxed); -- 2.34.1