mini-gmp mpz_{get,set}_d not fully compatible with GMP

Niels Möller nisse at
Tue Mar 13 14:12:27 UTC 2018

Vincent Lefevre <vincent at> writes:

> More than an order issue, this is undefined behavior. In C11:
> Multi-threaded executions and data races
>    4  Two expression evaluations conflict if one of them modifies a
>       memory location and the other one reads or modifies the same
>       memory location.
>   25  The execution of a program contains a data race if it contains
>       two conflicting actions in different threads, at least one of
>       which is not atomic, and neither happens before the other. Any
>       such data race results in undefined behavior.

Does C11 provide any way to initialize a local static variable, like in
recent C++? I.e., not code running before main, but code running the
first time the function is entered, and guaranteed to run just once?

> I don't think volatile matters. AFAIK, what you need is _Atomic (C11).

If we can make this thread safe with C11, I think it's fine to document
that mini-gmp requires C11 for thread safety. (I'd still prefer the
simpler way of reying on float.h constants, though).


Niels Möller. PGP-encrypted email is preferred. Keyid 368C6677.
Internet email is subject to wholesale government surveillance.

More information about the gmp-devel mailing list