From: Dario Russi Date: Tue, 14 Jan 2014 01:00:57 +0000 (-0800) Subject: fix AtomicHashMap race condition X-Git-Tag: v0.22.0~739 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=29d4c417a8a05c743d3a89310ebc1cbb2dfa0cfd;p=folly.git 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 --- 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);