Provides R-friendly threading functionality:
- thread safe versions of Rcpp's
checkUserInterrupt()
andRcout
, - an interruptible thread class that otherwise behaves like
std::thread
, - classes for the thread pool pattern and parallel for loops for easy and flexible parallelism.
The library is header-only, platform-independent, and only requires a C++11-compatible compiler.
For a detailed description of its functionality and examples, see the vignette or the API documentation.
Release version from CRAN:
install.packages("RcppThread")
Latest development version from github:
# install.packages("devtools")
devtools::install_github("tnagler/RcppThread")
- Pass
"RcppThread"
to thedepends
argument and"cpp11"
to theplugins
argument. For example:Rcpp::cppFunction('void func() { /* actual code here */ }', depends = "RcppThread", plugins = "cpp11")
- Add
before including any headers in your source code.
// [[Rcpp::plugins(cpp11)]] // [[Rcpp::depends(RcppThread)]]
- Add the line
CXX_STD = CXX11
to thesrc/Makevars(.win)
files of your package. - Add
RcppThread
to theLinkingTo
field of yourDESCRIPTION
file.
There are preprocessor options to replace all occurences of std::cout
and
std::thread
with calls to RcppThread::Rcout
and RcppThread::Thread
(provided that the RcppThread headers are included first). To enable this, use
#define RCPPTHREAD_OVERRIDE_COUT 1 // std::cout override
#define RCPPTHREAD_OVERRIDE_THREAD 1 // std::thread override
before including the RcppThread headers.