Skip to content

Commit

Permalink
fix reported deadlock ReactiveX#555
Browse files Browse the repository at this point in the history
  • Loading branch information
kirkshoop committed Aug 26, 2021
1 parent 9002d9b commit 810fd3f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Rx/v2/src/rxcpp/subjects/rx-subject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,16 @@ class multicast_observer
{
if (o.is_subscribed()) {
std::weak_ptr<binder_type> binder = b;
b->completer = std::make_shared<completer_type>(b->state, b->completer, o);
// must not hold lock in the case when add calls the lambda inline.
guard.unlock();
o.add([=](){
auto b = binder.lock();
if (b) {
std::unique_lock<std::mutex> guard(b->state->lock);
b->completer = std::make_shared<completer_type>(b->state, b->completer);
}
});
b->completer = std::make_shared<completer_type>(b->state, b->completer, o);
}
}
break;
Expand Down

0 comments on commit 810fd3f

Please sign in to comment.