R/fork.R

Defines functions isProcessForkedChild

Documented in isProcessForkedChild

#' Is the Current Process a Forked Child?
#'
#' Returns `TRUE` if the current process is a `fork()` of the process in which
#' RcppParallel was originally loaded.
#'
#' Intel TBB — the parallel backend used by `parallelFor()` and
#' `parallelReduce()` — does not support being used in a child process after
#' `fork()`. Packages that may be invoked from within `parallel::mclapply()`
#' or similar fork-based parallelism should call `isProcessForkedChild()` and
#' fall back to a serial code path when it returns `TRUE`.
#'
#' On Windows, which has no `fork()`, this always returns `FALSE`.
#'
#' @return A length-one logical.
#'
#' @examples
#' \dontrun{
#' library(RcppParallel)
#' isProcessForkedChild()
#' parallel::mclapply(1:2, function(i) RcppParallel::isProcessForkedChild())
#' }
#'
#' @export
isProcessForkedChild <- function() {
   .Call("isProcessForkedChild", PACKAGE = "RcppParallel")
}

Try the RcppParallel package in your browser

Any scripts or data that you put into this service are public.

RcppParallel documentation built on July 27, 2026, 5:08 p.m.