Closed ksahlin closed 2 years ago
This is not thread safe library. You are writing from multiple threads in log_stats_vec
.
As @slavenf says, if you call some_func
from multiple threads without guarding with a mutex you have a problem. Note that std::unordered_map
is also not thread safe.
Yes, that makes perfect sense. I have been struggling with a multithreading buserror for quite some time. Initially had vectors with logging stats per position in the vector (as hinted from variable names) then changed to hash tables in some desperate attempt.
Thanks for the quick reply!
Although, @martinus - if I:
(i) reserve enough slots in the table to prevent resizing of the table before threads start working, and (ii) each thread writes to its respective slot (which is the idea to remove the overhead of locks/critical sections),
would (i) and (ii) still pose a problem even if the implementation is not thread-safe? It is sort of discussed here (but in the context of writing to different slots in an array). In the attempt that generated my reported error, I have a hash table of thread_id : struct as key-value pairs.
that won't help because elements are shuffled around each time you insert/remove. Use a mutex.
Hi,
Thanks for a great implementation. I've been using it with success in my projects.
I may have found a bug (Segmentation fault) which happens when inserting
std::this_thread::get_id()
as key in arobin_hood::unordered_map
. It only failes for some runs, but never fails when I switchrobin_hood::unordered_map
tostd::unordered_map
. This leads me to believe that there are some thread_ids that cause an unexpected address lookup in the robin_hood version.Some relevant lines of code are below.