From ac8fd45b447938f06b126b94a4f95d1cbf3adcd4 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Mon, 7 Jul 2014 21:37:11 +0200 Subject: [PATCH] Make BufferParams::auto_packages() threadsafe --- src/BufferParams.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 3b85ff7a19..890f584e55 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -52,6 +52,7 @@ #include "support/filetools.h" #include "support/gettext.h" #include "support/Messages.h" +#include "support/mutex.h" #include "support/Translator.h" #include "support/lstrings.h" @@ -447,6 +448,14 @@ map const & BufferParams::auto_packages() { static map packages; if (packages.empty()) { + // We could have a race condition here that two threads + // discover an empty map at the same time and want to fill + // it, but that is no problem, since the same contents is + // filled in twice then. Having the locker inside the + // packages.empty() condition has the advantage that we + // don't need the mutex overhead for simple reading. + static Mutex mutex; + Mutex::Locker locker(&mutex); // adding a package here implies a file format change! packages["amsmath"] = N_("The LaTeX package amsmath is only used if AMS formula types or symbols from the AMS math toolbars are inserted into formulas"); -- 2.39.5