ReactiveX / RxCpp

Reactive Extensions for C++
Apache License 2.0
3.03k stars 390 forks source link

Deadlock when calling subject.get_subscriber().on_next() #529

Open david-hoze opened 4 years ago

david-hoze commented 4 years ago

Hi, I'm using a subject, e.g. like in the https://github.com/david-hoze/RxCppAsioReproduction example, which is of course subscribed to, and in some real world example getting a deadlock (for some reason I couldn't reproduce the problem synthetically, so no repo for this one.. :smile:).

When I protected it with a mutex like so:

{
    std::lock_guard<std::mutex> raii(my_mutex);
    my_subject.get_subscriber().on_next(my_value);
}

The deadlock stopped happening.. I read that subjects have no synchronization mechanisms, is that the reason why I deadlock?

If I for instance, use observe_on() when using my_subject.get_observable() like so:

my_subject.get_observable()
    .observe_on(my_coordination)
    ... // Other operators
    .subscribe(...);

Will it prevent the deadlock so that I can get rid of the mutex?

Thanks, David.