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

Radian hangs when printing from multi-threaded C++ code #494

Open
oelhammouchi opened this issue Sep 30, 2024 · 0 comments
Open

Radian hangs when printing from multi-threaded C++ code #494

oelhammouchi opened this issue Sep 30, 2024 · 0 comments

Comments

@oelhammouchi
Copy link

Hello, thank you very much for this amazing project! I've been experiencing an issue with radian hanging indefinitely when printing from threads in C++ that can't manage to debug. So far, it's only occurred when using the rcppspdlog library with the r_sink_mt logger designed to silence R CMD check warnings about printing to console. I've verified that it doesn't happen in the vanilla console.

He's an example snippet to illustrate the issue. If I compile the following function using Rcpp

#include <spdlog/fmt/ostr.h>
#include <RcppSpdlog>
#include <thread>

//' @export
// [[Rcpp::export]]
void testRsink() {
  std::string logname = "test_logger";
  auto sp = spdlog::get(logname);
  if (sp == nullptr) sp = spdlog::r_sink_mt(logname);
  spdlog::set_default_logger(sp);
  spdlog::set_pattern("[%H:%M:%S.%f] [%n] [%^%L%$] [thread %t] %v");
  spdlog::set_level(spdlog::level::warn);

  std::function warn_in_thread = [&]() {
    spdlog::warn("Something went wrong");
    return;
  };

  std::vector<std::thread> pool(4);
  for (std::thread& thrd : pool) {
    thrd = std::thread(warn_in_thread);
  }

  for (std::thread& thrd : pool) {
    thrd.join();
  }
}

and then run it in the R console, I get the output

> testRsink()
[16:21:25.695730] [test_logger] [W] [thread 8447909] Something went wrong
[16:21:25.695746] [test_logger] [W] [thread 8447910] Something went wrong
[16:21:25.695756] [test_logger] [W] [thread 8447911] Something went wrong
[16:21:25.695776] [test_logger] [W] [thread 8447912] Something went wrong

whereas radian just hangs without printing anything.

I guess it must have something to do with the infamous threading implementation in Python, but I'm not sure. Any idea how (or if) this can be solved?

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

1 participant