2

I am updating a CRAN package that needs C++ compilation. CRAN forbids std::cout << but allows Rcpp::Rcout <<. The latter however crashes the program in a multithreaded environment. I am using RcppParallel for multithreading. Is there an alternative without importing new R packages besides Rcpp and RcppParallel ?

Thank you!

A solution: put Rcpp::Rcout << ... in a tbb::spin_mutex locking scope.

user2961927
  • 1,290
  • 1
  • 14
  • 22
  • 4
    Rock, meet hard place. You _cannot_ use `std::cout` as CRAN Policy does not want you to mix two output streams. And _within a parallel section you cannot use `Rcpp::Rcout`_ as you cannot call back to R from such a section. So rethink your approach and need for printing. This is not going to be solved by another package. – Dirk Eddelbuettel Apr 08 '18 at 22:11
  • 1
    What he said before I said it.... – coatless Apr 08 '18 at 22:12
  • @DirkEddelbuettel Thank you for the comment Dirk. I kept messing with this and found putting `Rcout << ...` in a mutex scope works out fine. – user2961927 Apr 09 '18 at 17:44

0 Answers0