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

Unable to stop an application with ctrl+c with handleQuitSignals #925

Open
LoreMoretti opened this issue Jan 22, 2025 · 4 comments
Open
Labels
bug Something isn't working

Comments

@LoreMoretti
Copy link
Contributor

LoreMoretti commented Jan 22, 2025

I have written a cpp application which spawns 2 threads. Each thread is running an advanceable runner.

I am trying to use the BipedalLocomotion::System::handleQuitSignals to implement the logic that should stop the application when clicking ctrl+C.

It follows the portion of the application related to this logic:

  // handle the ctrl+c signal
  BipedalLocomotion::System::handleQuitSignals([&]() {
    plannerRunner.stop();
    controllerRunner.stop();
  });

  // barrier to synchronize the controller and the planner
  auto barrier = BipedalLocomotion::System::Barrier::create(2);

  // run the planner and controller
  auto plannerThread = plannerRunner.run(barrier);
  auto controllerThread = controllerRunner.run(barrier);

  // wait for the planner and controller threads to finish
  while (plannerRunner.isRunning() && controllerRunner.isRunning()) {
    using namespace std::chrono_literals;

    BipedalLocomotion::clock().yield();
    BipedalLocomotion::clock().sleepFor(200ms);
  }

  // stop the the planner and controller threads
  plannerRunner.stop();
  controllerRunner.stop();

What happens is that when clicking ctrl+c most of the times the application does not get stopped.

@GiulioRomualdi
Copy link
Member

This is really tricky and dangerous. I was wondering if you are using library which carch the ctrl-c.

Cc @traversaro

@traversaro
Copy link
Collaborator

What happens is that when clicking ctrl+c most of the times the application does not get stopped.

Can you check if the lambda is getting called or not? Can you provide more context of how the handleQuitSignals is being called? Are you calling it from a main() function?

@GiulioRomualdi GiulioRomualdi added the bug Something isn't working label Jan 24, 2025
@LoreMoretti
Copy link
Contributor Author

LoreMoretti commented Jan 28, 2025

Can you check if the lambda is getting called or not? Can you provide more context of how the handleQuitSignals is being called? Are you calling it from a main() function?

Yes I am calling it from a main() function.

I have verified that when clicking ctrl+c, the function handleQuitSignals does not get invoked.

@GiulioRomualdi
Copy link
Member

Are you able to provide a minimum example like a main wirh an empty synchronous thread running

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants