ReactiveX / RxCpp

Reactive Extensions for C++
Apache License 2.0
3.05k stars 395 forks source link

subjects::synchronize lock with current_thread or immediate scheduler #491

Closed lebdron closed 5 years ago

lebdron commented 5 years ago
rxcpp::composite_subscription lifetime;
rxcpp::subjects::synchronize<int, rxcpp::identity_one_worker> sub(
    rxcpp::identity_current_thread(), lifetime);

sub.get_subscriber().on_next(1);
lifetime.unsubscribe();

This code locks in drain_queue https://github.com/ReactiveX/RxCpp/blob/7c79c18ab252eb37bcf122c75070f8d557868c08/Rx/v2/src/rxcpp/subjects/rx-synchronize.hpp#L60 because the lock in on_next is not unlocked https://github.com/ReactiveX/RxCpp/blob/7c79c18ab252eb37bcf122c75070f8d557868c08/Rx/v2/src/rxcpp/subjects/rx-synchronize.hpp#L107

Should it be safe to call unlock before these lines? https://github.com/ReactiveX/RxCpp/blob/7c79c18ab252eb37bcf122c75070f8d557868c08/Rx/v2/src/rxcpp/subjects/rx-synchronize.hpp#L91-L92 schedule should be thread-safe by contract if I am not mistaken.

kirkshoop commented 5 years ago

Yes, I believe that it would be safe to unlock before the call to schedule.