On 11/24/2014 04:10 PM, Jean-Marc Lasgouttes wrote:
Le 24/11/2014 21:53, Georg Baum a écrit :
Richard Heck wrote:

Can you explain in language I can understand why simply /reading/ this
variable
in separate threads could cause this kind of problem? I'm very confused.

I guess the basic principle how copy-on-write works is clear? If not, see
e.g. http://en.wikipedia.org/wiki/Copy-on-write.

The problem is not the read access. This is safe. The problem is write
access and can be illustrated by the following code:

std::string s1("foo");
std::string s2(a);
std::string s3 = s1;

OK, could you know explain the same in terms of Language::babel(), which is a const function? Between which objects is the representation shared?

It might be that understanding that is useless because the problem is general as you say. But it might happen too that it helps us to understand better what happens.

Yes, the part that still confuses me is when you (Georg) say:

After changing one string (e.g. a):

s1 = "bar";

I can see why this could cause problems. But it is what shouldn't happen here. Not only is Language::babel() const, but the Language object we are using to access it is const. And babel_ is not mutable.

Maybe there is some other common string that *is* being changed, though, and babel_ is somehow a red herring?

Richard

Reply via email to