Memory barrier for fat initialization
Torbjörn Granlund
tg at gmplib.org
Thu Jan 15 17:32:43 UTC 2015
Victor Shoup <shoup at cs.nyu.edu> writes:
I've recently worked on making some thread safe code,
and learned all about the new memory model in the C11
and C++11 standards (these are thankfully compatible models).
There's lot of stuff online (look for C11 atomics or C++11 atomics,
and buzzwords like memory_order_release).
The point is: this can (in theory) be all done at the C level
in a portable and efficient way...although compilers are
still playing catchup...but it might be the right way to go
"moving forward"
We tend to be quite conservative when it comes to the required build
environment, and asking for C11 would make GMP much less portable.
The reasoning behind our conservatism is that being a library, GMP would
limit the portability of dependent libraries and application by asking
for some limited-availability feature.
For the fat initialisation problem, optimistic initialisation but then using
asm volatile ("some-synch-insn")
before we set the __gmpn_cpuvec_initialized flag, would on modern
architectures be no problem. Such architectures had weak memory
ordering from their first revisions, and also provided an adequate
some-synch-insn from the start.
--
Torbjörn
Please encrypt, key id 0xC8601622
More information about the gmp-devel
mailing list