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

[Enhancement] Detecting user interrupt #65

Open
asardaes opened this issue Apr 27, 2018 · 1 comment
Open

[Enhancement] Detecting user interrupt #65

asardaes opened this issue Apr 27, 2018 · 1 comment

Comments

@asardaes
Copy link

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.

@franzbischoff
Copy link
Contributor

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

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

2 participants