Provides a C++11-style thread class and thread pool that can safely
be interrupted from R. See Nagler (2021)
Provides R-friendly threading functionality:
checkUserInterrupt()
and Rcout
,std::thread
,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 the depends
argument and "cpp11"
to the plugins
argument. For example:
Rcpp::cppFunction('void func() { /* actual code here */ }',depends = "RcppThread", plugins = "cpp11")
Add
// [[Rcpp::plugins(cpp11)]]// [[Rcpp::depends(RcppThread)]]
before including any headers in your source code.
CXX_STD = CXX11
to the src/Makevars(.win)
files of your package.RcppThread
to the LinkingTo
field of your DESCRIPTION
file.std::cout
and std::thread
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.
Limit number of threads in unit tests.
Fixed typos in package vignette.
BUG FIXES
Fix portability issues related to native_handle_type
.
Fix signed/unsigned comparison in parallelFor()
.
Fix signed/unsigned warnings in unit tests.
DEPENDENCIES
NEW FEATURES
New vignette available, see browseVignettes("RcppThread")
.
New functions parallelFor()
and ForEach()
allowing parallel for
loops
with load balancing. Can also be called as method of a ThreadPool
.
Options to override std::thread
and std::cout
with RcppThread equivalents
using preprocessor variables RCPPTHREAD_OVERRIDE_THREAD
and
RCPPTHREAD_OVERRIDE_COUT
.
Several minor performance optimizations.
NEW FEATURE
ThreadPool::map()
that allows to map a function a list of items.NEW FEATURE
ThreadPool
can now be intantiated with zero threads in the pool. It
will then do all work pushed to it in the main thread.NEW FEATURE
ThreadPool
has a new method wait()
that waits for all jobs to be done
without joining the threads. This way the thread pool can be re-used for
different types of tasks that need to be run sequentially.BUG FIX
DEPENDS
R (>= 3.3.0)
.BUG FIX
BUG FIX
Rcout
instance in header file (#9; couldn't link
shared library on r-hub, see discussion in #8)