multithreading - C++ std::map - thread safe if one thread writes and another reads with always different keys? -
this question has answer here:
thread writes std::map key c
thread b reads std::map key d
if guaranteed keys not overlap, thread safe?
since std::map uses tree-structure inside, imagine there problems read while being mutated.
if std::map not work, std::unordered_map better?
- if writing mean changing value of already existing entry associated key c, answer (i believe) yes.
- if writing mean (potentially) inserting new elements (or removing them), answer definitively no.
although not authoritative source, www.cplusplus.com has section potential data races each function.
Comments
Post a Comment