Not sent to RT, to <openssl-dev> only.

Alternatives would be (a) using a new lock for safe static initialization,
or (b) more code duplication to avoid the need for an explicit pointer
(there could be two separate implementations for the higher-level
routines).  However, given the 1% performance penalty, that's a minor issue
at this point.
While if (functiona==NULL || functionb==NULL) { asssign functiona,
functionb } can be unsafe, I'd argue that if (functiona==NULL) { assign
functiona } followed by if (functionb) { assign functionb } is.

That's not thread-safe.  There's no memory barrier so the writes can
be reordered.  The compiler itself could reorder those instructions.

I want to remind that in this case assignments are constant in sense that all threads will assign same value. So that disjoint if's work out even if threads are reading/writing out of order. As for reorder by compiler. No, it won't do that. If it actually would have this option, then "if (ptr) *ptr" wouldn't be safe. If compiler [or hardware] does that kind of speculation it is also obliged to verify the assumption and act accordingly. Or do you mean that it could reorder it as if-if-assign-assign? This is not a problem. The only *formally* valid concerns are pointed by Bodo in another message, and they are that function[ab] are misaligned (and therefore access is not atomic), and that they are used for something else earlier. As for latter. If compiler was to use explicitly initialized shared variable for something else, it would have to do in a way invisible to program code. It is only possible after *full* inter-procedural analysis for given *binary*. But then analyzer would have to be aware of transition from single- to multi-threaded operation and stop using variable for something else before multi-threaded part [and even initialize it accordingly]. And as for former. In the context one should recognize that we are not talking about *universally* portable code. The code in question *is* platform-specific and we are free to take into consideration such implementation specifics as object alignment [in supported compilers].
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       openssl-dev@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to