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

simple question about update_fn #154

Open
arjen-Lee1993 opened this issue Feb 17, 2023 · 1 comment
Open

simple question about update_fn #154

arjen-Lee1993 opened this issue Feb 17, 2023 · 1 comment

Comments

@arjen-Lee1993
Copy link

there are several threads concurrently writing on a same value in the hashmap,so i need "update_fn" rather than "update" to lock the value to avoid overwriting.
my input function seems like void fn(mapped_type&, param1 xx, param2 xx ....)
i need more extra input params, but the update_fn may not supported.
can u give me some advices to solve this problem?

@manugoyal
Copy link
Contributor

Hi @arjen-Lee1993. update_fn can only provide mapped_type&, as that is the only information stored in the hashtable. If the additional parameters are coming from somewhere else, maybe they can be captured by the lambda you provide to update_fn? E.g.

map.update_fn(k, [&param1, &param2, &fn](mapped_type& m) { fn(m, param1, param2); });

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