[Rcpp-devel] thread safety RNG

konrad konrad_kraemer at yahoo.de
Fri Oct 21 12:15:11 CEST 2022


Dear all,


my package ast2ast includes currently some random number generation 
functions (e.g. R::dunif) within the C++ code.

So my question is whether the RNG functions in the namespace 'R' are 
thread safe?

Moreover, I would like to know how to handle the functions GetRNGstate() 
and PutRNGstate(). I guess that these functions modify a global 
variable. Thus, it is necessary to lock these functions with a mutex.

As a side note ast2ast translates R to C++ code. This code is thread 
safe in the sense that no static methods are implemented or that memory 
is associated with functions or global variables. Therefore, it would 
also be cool if the RNGs could abe used in parallel.


Thank you very much for your help.


All the best,


Konrad



More information about the Rcpp-devel mailing list