summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric Nugteren <web@cedricnugteren.nl>2023-07-08 20:08:00 +0200
committerGitHub <noreply@github.com>2023-07-08 20:08:00 +0200
commit6762e8480c25b6755bd174aedb1bd0ef5f1ad478 (patch)
tree9b922e286d58ef602b1fe775abd8f9fdca2abe26
parent83bd474edadefff46d284f5e5c85fee0a7db0531 (diff)
Fix a multithreading bug related to storing objects in the cache (#495)
-rw-r--r--CHANGELOG1
-rw-r--r--src/cache.cpp7
2 files changed, 7 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 60ce865f..ecd86dec 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,5 +1,6 @@
Development version (next version)
- Fix pointer error in pyclblast on ARM
+- Fix a multithreading bug related to storing objects in the cache
- Added tuned parameters for many devices (see doc/tuning.md)
Version 1.6.0
diff --git a/src/cache.cpp b/src/cache.cpp
index e15a72a5..6accf9a5 100644
--- a/src/cache.cpp
+++ b/src/cache.cpp
@@ -56,7 +56,12 @@ void Cache<Key, Value>::Store(Key &&key, Value &&value) {
// emplace() into a map
auto r = cache_.emplace(std::move(key), std::move(value));
if (!r.second) {
- throw LogicError("Cache::Store: object already in cache");
+ // The object is already in cache. This can happen if two threads both
+ // checked the cache for an object, both found that it isn't there, then
+ // both produced the object (e.g. a compiled binary) and try to store it
+ // in the cache. The first one will succeed normally, the second one will
+ // hit this point. We simply return in this case.
+ return;
}
#else
// emplace_back() into a vector