A quick search was not pulling up anything I could use as a starting point. If I wanted to learn threading as I know it in Java or c#, what resource and where should I look for c++ multithreading?
A quick search was not pulling up anything I could use as a starting point. If I wanted to learn threading as I know it in Java or c#, what resource and where should I look for c++ multithreading?
this site has all the info you would need.
Beware that unlike Java and C#, it's very important in C++11 to make all threaded code that uses the standard library const correct.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
Const correct code is thread safe in c++11, see here:C++ and Beyond 2012: Herb Sutter - You don't know [blank] and [blank] | Channel 9
Last edited by Shakti; 01-21-2013 at 08:52 AM.
[Edit]Sorry for the needlessly aggressive original. I've rewritten the post with more context.[/Edit]
Yog Sothoth!Const correct code is thread safe in c++11
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.
Soma
Last edited by phantomotap; 01-21-2013 at 11:07 AM.
Yah that was a wreckless comment, hindsight is 20/20....should have dumped the link only!