Deadlock possible between rcu_retire and synchronize_rcu
- Dominant language
- C++
- Stars
- 30.5k
- Forks
- 5.9k
- PR merge metrics
- No merged PRs in 30d
Description
If one thread is calling synchronize_rcu() and another rcu_retire(), it's possible for them to deadlock against each other. This is a generalization of the specific constraint that `synchronize_rcu()` should not be called when the thread has a reader active or it will deadlock against itself.
I'm unsure if this is a bug, except the comments in `Rcu-inl.h` indicate the author intends the behavior to be handled.
```
// Note that it's likely we hold a read lock here,
// so we can only half_sync(false). half_sync(true)
// or a synchronize() call might block forever.
```
Below is a test case which illustrates this issue. There are a couple of comments embedded there which indicate possible work arounds.
```
TEST_CASE("B") {
folly::Baton guarded, sync_ready;
std::thread t1([&] {
folly::rcu_reader guard;
guarded.post();
sync_ready.wait();
std::this_thread::sleep_for(10ms);
// guard.unlock(); // << uncomment this line to resolve
folly::rcu_retire(new std::string());
});
std::thread t2([&] {
guarded.wait();
sync_ready.post();
folly::synchronize_rcu(); // change to folly::rcu_retire() to resolve
});
t1.join();
t2.join();
}
```
Contributor guide
Assessment
This issue has not been assessed yet.