RcppParallel
RcppParallel copied to clipboard
[Enhancement] Detecting user interrupt
I don't know if it would be technically possible, but it would be nice to be able to use something like Rcpp::checkUserInterrupt inside a thread.
I'm currently using this approach (also to add a progress bar):
// worker structure
RcppProgress::Progress *p;
#if RCPP_PARALLEL_USE_TBB
tbb::mutex m;
#else
tthread::mutex m;
#endif
// ...
// this is inside the void operator()(std::size_t begin, std::size_t end)
for(int i = begin; i < end; i++) {
if (i % 100 == 0) {
RcppThread::checkUserInterrupt();
m.lock();
p->increment();
m.unlock();
}
}