Hi David, thanks for the detailed explanation but I haven't understood all of it. I should probably look at the code. So: 1) I suppose you cannot just make the private mutable a local variable? 2) Sometimes I found it to be useful to work with sets of memory addresses/pointers when it comes to string comparisons or lookups. Not sure if this is applicable here. 3) As far as I understand getIdByName it the evil part, here, so instead of locking its access I could also keep a global read-only lookup map outside your container? Gruß Johannes Am 25.09.2013 10:48, schrieb Weese, David:
Hi Johannes, there is a mutable private string inside the NameCache that is not thread-safe. So although getIdByName is used with a constant name store cache, there will be some concurrent write accesses if you use it with multiple threads. Internally a name store cache is a set of ids (unsigned ints) that are sorted lexicographically with respect to the corresponding names in the name store (a StringSet). The std::set::find() only supports to search for keys of the set, i.e. ids. That means if a random string needs to be looked up we first store it temporarily in a private mutable string inside the less operator and search for the id -1 to signal the less operator that this string should be compared with the strings inside the name store. If the std::set would be more generic in the types that find and the less operator would accept we wouldn't need to do it this way. So right now, you should put your lookups inside an critical section until we found a better solution. Cheers, David