multi_index: thread safety
Hi, I have a multi_index container and would like to make concurrent READs. Is it thread-safe? I mean that there could be mutable members inside the object, so calling formally const functions leaded to concurrent writes.
Joaquín M López Muñoz answers: http://stackoverflow.com/questions/23265044/does-modify-different-field-valu... -----Original Message----- From: Boost-users [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Matwey V. Kornilov Sent: Sunday, March 08, 2015 1:12 PM To: boost-users@lists.boost.org Subject: [Boost-users] multi_index: thread safety Hi, I have a multi_index container and would like to make concurrent READs. Is it thread-safe? I mean that there could be mutable members inside the object, so calling formally const functions leaded to concurrent writes. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Matwey V. Kornilov
Hi,
I have a multi_index container and would like to make concurrent READs. Is it thread-safe? I mean that there could be mutable members inside the object, so calling formally const functions leaded to concurrent writes.
Adding to Ernest's answer: if your formally const function changes the value of some mutable data member, then concurrent access is NOT safe. For instance: struct X { int x; mutable std::size_t count; int get_x()const { ++count; return x; } }; Concurrent execution of X::get_x is not safe. This has nothing to do with Boost.MultiIndex, by the way; if your problem is different please answer back. Joaquín M López Muñoz Telefónica
08.03.2015 18:06, Joaquin M Lopez Munoz пишет:
Matwey V. Kornilov
writes: Hi,
I have a multi_index container and would like to make concurrent READs. Is it thread-safe? I mean that there could be mutable members inside the object, so calling formally const functions leaded to concurrent writes.
Adding to Ernest's answer: if your formally const function changes the value of some mutable data member, then concurrent access is NOT safe. For instance:
struct X { int x; mutable std::size_t count;
int get_x()const { ++count; return x; } };
Concurrent execution of X::get_x is not safe. This has nothing to do with Boost.MultiIndex, by the way; if your problem is different please answer back.
Yes, It is clear to me. This is why I asked if there any mutable inside MultiIndex.
participants (3)
-
Ernest Zaslavsky
-
Joaquin M Lopez Munoz
-
Matwey V. Kornilov