Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfaults in run_loop #19

Closed
Noggog opened this issue Mar 5, 2019 · 4 comments
Closed

Segfaults in run_loop #19

Noggog opened this issue Mar 5, 2019 · 4 comments
Assignees

Comments

@Noggog
Copy link

Noggog commented Mar 5, 2019

Hey tetsurom,
Thanks for your work on the library!

I don't know if this is an issue report or simply a misuse on my part, but I am getting some segfaults inside the run loop, given a certain threading setup:

It seems to be an interaction between firing a subject from a non-GUI thread, which is being observed on the GUI thread. This alone doesn't cause issue, until any unrelated subscription makes use of "sample_with_time" on the GUI thread, which all together seems to cause some issues and segfault.

  rxqt::run_loop rxqt_run_loop;
  rxcpp::subjects::subject<bool> test;
  rxcpp::subjects::subject<bool> test2;

  // Subject to be fired subscribes on the GUI loop
  test.get_observable()
    .observe_on(rxqt_run_loop.observe_on_run_loop())
    .subscribe([](bool) { });

  // Unrelated subject samples on the GUI loop
  test2.get_observable()
    .sample_with_time(std::chrono::milliseconds(25), rxqt_run_loop.observe_on_run_loop())
    .subscribe([](bool){ });

  // Fire first subject from another thread.
  rxcpp::observable<>::range(1, 10000)
    .observe_on(rxcpp::synchronize_new_thread())
    .subscribe([=](int) {
      test.get_subscriber().on_next(true);
    });

I have tested another alternative, where I fire the subject on the GUI thread instead, which leads to the same results:

  rxcpp::observable<>::range(1, 10000)
    .observe_on(rxcpp::synchronize_new_thread())
    .tap([=](int) {
      // Some work on the other thread
      std::this_thread::sleep_for(std::chrono::seconds(2));
    })
    .observe_on(rxqt_run_loop.observe_on_run_loop())
    .subscribe([=](int) {
      test.get_subscriber().on_next(true);
    });;

The segfault occurs at this line in the rxqt library:

if (!timer.isActive() || ms_till_task.count() < timer.remainingTime())

I did wonder if this had to do with the rxcpp bug mentioned here:
ReactiveX/RxCpp#486
but I had the feeling it was more related to the use of QTimer in rxqt_run_loop

Let me know if you have any tips or insight. Thanks!

@Noggog
Copy link
Author

Noggog commented Mar 5, 2019

One thing I've noticed: If I just create my own QThread, and fire the test subject with that, everything functions properly. It's only when trying to fire the test subject off an Rxcpp-spawned thread that it collides, from my experience.

@tetsurom
Copy link
Owner

Hi Noggog, I believe now this is fixed.

Thank you for the report.

@Noggog
Copy link
Author

Noggog commented Mar 16, 2019

Will take a look and report back on monday. 8) Thanks!

@Noggog
Copy link
Author

Noggog commented Mar 21, 2019

Looks good so far! Will reopen another case if anything comes up.

Thanks a lot!

@Noggog Noggog closed this as completed Mar 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants