Le 13/08/2016 à 16:45, Enrico Forestieri a écrit :
commit 7113fb669dcd193295308c44ee2213aa437e38b2
Author: Enrico Forestieri <for...@lyx.org>
Date:   Sat Aug 13 17:43:03 2016 +0200

    Correct comment

    According to C++11 rules, static locals are thread safe for
    the first-time initialization.

    See also:
    
http://stackoverflow.com/questions/12302057/c11-safe-double-checked-locking-for-lazy-initialization-possible
---
 src/graphics/PreviewLoader.cpp |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/graphics/PreviewLoader.cpp b/src/graphics/PreviewLoader.cpp
index 88f49b0..f3bf437 100644
--- a/src/graphics/PreviewLoader.cpp
+++ b/src/graphics/PreviewLoader.cpp
@@ -102,7 +102,7 @@ lyx::Converter const * setConverter(string const & from)
                                << "\" format has been defined.");
                });
 #else
-       // This is not thread-safe.
+       // This is also thread-safe according to §6.7.4 of the C++11 standard.
        static bool first = true;
        if (first) {
                first = false;



I think the threading issue here is that the static variable is used
for synchronizing the calls in the subsequent line. Maybe what you mean
instead by "thread-safe" is that (short of having a drop-in replacement
such as call_once) we do not want to spend so much energy in this
problem because its effect would be trivial. Saying so in a comment
would be helpful for future people reviewing the use of statics in the code.

Another thing I was not sure about is whether it was really intended
that it will only output one error message independently of the value of
"from". But then I see that it is only ever called for from="lyxpreview".


Reply via email to