As #171 discussed, using TBB after fork isn't really safe. The docs say so explicitly.
In a downstream package, there isn't really a good check to see if the process was forked after TBB was loaded.
The reason that this isn't possible to check in downstream packages is RcppParallel (and therefore TBB) can be loaded earlier in the process. Concretely:
library(RcppParallel) # loads / initializes TBB in parent
parallel::mclapply(1:2, function(i) {
library(qs2)
qs2::qs_read(..., nthreads = 2) # crash
})
But since RcppParallel is the only path to load TBB, the check could be simple as long as it is in RcppParallel:
Something like:
#include <sys/types.h>
#include <unistd.h>
static const pid_t rcpp_parallel_load_pid = getpid();
// export this function
bool tbb_is_safe_to_use() {
return getpid() == rcpp_parallel_load_pid;
}
Could this be added in?
As #171 discussed, using TBB after fork isn't really safe. The docs say so explicitly.
In a downstream package, there isn't really a good check to see if the process was forked after TBB was loaded.
The reason that this isn't possible to check in downstream packages is RcppParallel (and therefore TBB) can be loaded earlier in the process. Concretely:
But since RcppParallel is the only path to load TBB, the check could be simple as long as it is in RcppParallel:
Something like:
Could this be added in?