Commit b29f0eb3 authored by Maged Michael's avatar Maged Michael Committed by Facebook GitHub Bot

hazptr_obj_cohort: Fix race condition

Summary:
Fix race condition in hazptr_obj_cohort deactivation

Race condition:
- Thread T1 is doing asynchronous reclamation of objects.
- Thread T2 starts deactivating cohort C.
- T1 reclaims an object that its destructor retires a tagged object A that belongs to cohort C.
- T1 checks that C is active.
- T2 sets C.active_ to false.
- T2 pops and reclaims the objects in C's list.
- T1 pushes A in C's list
- T2 expects to find C's list empty but it is not. Assertion failure.

With the fix.
- Thread T1 is doing asynchronous reclamation of objects.
- Thread T2 starts deactivating cohort C.
- T1 reclaims an object that its destructor retires a tagged object A that belongs to cohort C.
- T1 checks that C is active.
- T2 sets C.active_ to false.
- **T2 waits for T1 to release the lock on the domain tagged list**
- T1 pushes A in C's list
- **T1 releases the lock**
- **T2 cleans up C's objects in the domain tagged list**
- **No subsequent asynchronous reclamation of objects in the domain will involve objects that belong to C**
- T2 pops and reclaims the objects in C's list **including A**
- T2 finds C's list empty as expected.

Reviewed By: yfeldblum

Differential Revision: D23947490

fbshipit-source-id: 943664e61190da7b4ad1bb31ac47609bdea2314d
parent 005bacc2
......@@ -325,15 +325,15 @@ class hazptr_obj_cohort {
void shutdown_and_reclaim() {
DCHECK(active());
clear_active();
if (pushed_to_domain_tagged_.load(std::memory_order_relaxed)) {
default_hazptr_domain<Atom>().cleanup_cohort_tag(this);
}
if (!l_.empty()) {
List l = l_.pop_all();
clear_count();
Obj* obj = l.head();
reclaim_list(obj);
}
if (pushed_to_domain_tagged_.load(std::memory_order_relaxed)) {
default_hazptr_domain<Atom>().cleanup_cohort_tag(this);
}
DCHECK(l_.empty());
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment