| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
3.7 Reentrancy
GMP is reentrant and thread-safe, with some exceptions:
-
If configured with ‘--enable-alloca=malloc-notreentrant’ (or with
‘--enable-alloca=notreentrant’ when
allocais not available), then naturally GMP is not reentrant. -
mpf_set_default_precandmpf_inituse a global variable for the selected precision.mpf_init2can be used instead, and in the C++ interface an explicit precision to thempf_classconstructor. -
mpz_randomand the other old random number functions use a global random state and are hence not reentrant. The newer random number functions that accept agmp_randstate_tparameter can be used instead. -
gmp_randinit(obsolete) returns an error indication through a global variable, which is not thread safe. Applications are advised to usegmp_randinit_defaultorgmp_randinit_lc_2expinstead. -
mp_set_memory_functionsuses global variables to store the selected memory allocation functions. -
If the memory allocation functions set by a call to
mp_set_memory_functions(ormallocand friends by default) are not reentrant, then GMP will not be reentrant either. -
If the standard I/O functions such as
fwriteare not reentrant then the GMP I/O functions using them will not be reentrant either. -
It’s safe for two threads to read from the same GMP variable simultaneously,
but it’s not safe for one to read while another might be writing, nor for
two threads to write simultaneously. It’s not safe for two threads to
generate a random number from the same
gmp_randstate_tsimultaneously, since this involves an update of that variable.
| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on March 31, 2014 using texi2html 5.0.
