Skip to main content

Module worker

Module worker 

Source
Expand description

Worker thread infrastructure for safe Rust-R FFI.

§Public API

§Feature gate: worker-thread

Without the worker-thread cargo feature, all calls execute inline on R’s main thread:

  • with_r_thread(f) runs f() directly (panics if not on main thread)
  • run_on_worker(f) runs f() directly, returns Ok(f())

With the feature enabled, a dedicated worker thread is spawned at init time. with_r_thread routes calls from the worker back to main, and run_on_worker dispatches closures to the worker with bidirectional communication.

§Initialization

[miniextendr_runtime_init] must be called from R’s main thread before any R FFI APIs. Typically done in R_init_<pkgname>().

Statics§

R_MAIN_THREAD_ID 🔒

Functions§

assert_runtime_initialized 🔒
Panic if the runtime hasn’t been initialized.
has_worker_context 🔒
Check whether the current thread has a worker routing context.
is_r_main_thread
Check if the current thread is R’s main thread.
with_r_thread
Execute a closure on R’s main thread, returning the result.