Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use parallel_flat_hash_map #261

Open
realwzc opened this issue Nov 27, 2024 · 3 comments
Open

How to use parallel_flat_hash_map #261

realwzc opened this issue Nov 27, 2024 · 3 comments

Comments

@realwzc
Copy link

realwzc commented Nov 27, 2024

Dear Author,

After reading your code, I have two questions I’d like to ask:

  • When using parallel_flat_hash_map and passing a lock type through the template parameter, can the map still support operations like:
auto iter = map.find(key);  
if (iter != map.end()) {  
    map.erase(iter);  
}  

or

map[key] = value;  
  • Does node_hash_map prevent crashes caused by rehashing during concurrent reads and writes of different keys? Our program can guarantee that different threads only read or write distinct keys.

Best regards,

@greg7mdp
Copy link
Owner

  • can the map still support operations like

No, these APIs cannot be made thread safe, but phmap has extended APIs which are thread safe (basically providing a lambda which is called under the lock protection). See this paragraph at the end of the README.

image

@realwzc
Copy link
Author

realwzc commented Nov 27, 2024

Thank you for your response, but if I want to delete this key, how should I do it? Is using map.erase(key); thread-safe?

@greg7mdp
Copy link
Owner

Yes, erase(key) is safe. If you want to check something before erasing the key, there is erase_if.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants