Threading in C++

This is a discussion on Threading in C++ within the C++ Programming forums, part of the General Programming Boards category; A quick search was not pulling up anything I could use as a starting point. If I wanted to learn ...

Manasij Mukherjee | gcc-4.9.2 @Arch Linux Slow and Steady wins the race... if and only if :1.None of the other participants are fast and steady.
2.The fast and unsteady suddenly falls asleep while running !

[Edit]Sorry for the needlessly aggressive original. I've rewritten the post with more context.[/Edit]

Const correct code is thread safe in c++11

Yog Sothoth!

Will you please never repeat only half of that discussion again? It is hard enough to teach `const' and `mutable'.

Your statement lacks crucial context.

For that to be true, `const' operations MUST be composed of only read operations across threads or be made thread-safe using measures internal to the operation.

If neither of those holds true for a given class, it is, in fact, trivial to write a class that is `const'-correct and `mutable'-correct. Consider a class that caches to a `mutable' variable being read from a `const' method: from the point of view of the `const' `this' the `mutable' variable is a read operation even though a second thread, with a reference to the same `this', may use an operation that writes to the `mutable' variable. For the standard library guarantees to hold, the reads and writes to that `mutable' variable must be internally atomic so that they outside world really does get to assume that such operations are thread-safe making the implementation, of the standard library, thread-safe by virtue.

There is no magic to this "new" situation; if you write internals of a class such that they aren't thread-safe with respect to `const' and `mutable' using those keywords correctly will do nothing for you. The standard library implementation in question will probably choke on your class.