Skip to content

Is there a way to update and erase in a thread-safe way? #287

Answered by arximboldi
vrn-sn asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @VarunSaini02!

Here are some conceptual clarifications:

  1. The erase and update functions, like every single const method in an Immer container is thread safe. They are "thread safe" also when applied in multiple steps. I wouldn't advise to mutate the map inside the update() function as it can lead to problems, but a multi-step approach should both be safer and easier to understand.

  2. The only method that is not thread-safe in an immer::map is assignment, the operator=. This means that you can not, in an unprotected manner, read a variable of type immer::map and the same time write to it in another thread. This means that if you have a variable called my_map that is shared across thread…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@vrn-sn
Comment options

@arximboldi
Comment options

Answer selected by vrn-sn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants