I am using RcppThread for parallelism in an Rcpp function. What is the preferred way to throw an error in the middle of a parallel loop? R's API is single threaded, so I assume Rcpp::stop() is not thread safe. RcppThread provides means for thread safe cout and CheckUserInterrupt but not, so far as I can tell, a thread safe stop.
An example of what I'm trying to do:
#include <RcppThread.h>
// [[Rcpp::plugins(cpp11)]]
// [[Rcpp::depends(RcppThread)]]
void myfun() {
// parallel loop
RcppThread::parallelFor(0, 100, [](int j){
// do something that causes an error
Rcpp::stop("Is this error unsafe?");
});
}