commit 27ae162be7d88e9fc31764f8705602a238cafd1c
parent bdcb12dca7624752f0f69d9c680ca0ccaee30dde
Author: Matt Demanett <matt@demanett.net>
Date: Thu, 21 Nov 2019 00:11:31 -0500
Fix initialization race condition (can cause crash). #79
Diffstat:
1 file changed, 3 insertions(+), 0 deletions(-)
diff --git a/src/dsp/table.hpp b/src/dsp/table.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <assert.h>
+#include <mutex>
#include "base.hpp"
@@ -41,6 +42,7 @@ protected:
template<class T, int N> class StaticTable {
private:
Table* _table = NULL;
+ std::mutex _lock;
StaticTable() {
}
@@ -56,6 +58,7 @@ public:
static const Table& table() {
static StaticTable<T, N> instance;
+ std::lock_guard<std::mutex> lock(instance._lock);
if (!instance._table) {
instance._table = new T(N);
instance._table->generate();