RcppParallel icon indicating copy to clipboard operation
RcppParallel copied to clipboard

[Enhancement] Detecting user interrupt

Open asardaes opened this issue 7 years ago • 1 comments

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.

asardaes avatar Apr 27 '18 17:04 asardaes

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();
  }
}

franzbischoff avatar Dec 28 '20 16:12 franzbischoff