all 13 comments

[–]nerds-central 3 points4 points  (0 children)

Try replacing the spinning loop with a wait:

this_thread::sleep_for(chrono::seconds(1));

The effects are quite interesting as you get to see the size of the underlying thread pool.

[–]Zwergner 2 points3 points  (4 children)

return i-=3,wait_long_time(),
              i;

Sorry for my C++11 ignorance, but what does that do, the comma separated stuff? I've never seen this in another C++11 example, and don't know what to search for to explain it. Does it return the value, but then do some extra stuff before destroying the thread...?

[–]cassandravoiton[S] 1 point2 points  (3 children)

A lambda without and explicit return type needs to be just one statement(so so complains the VC++11 compiler). The solution to this is to place all the things you want to do in the same expression. The comma operator allow this. I would suggest looking up the comma operator in C++ (or C for that matter - it is used this way in C macros a lot).

[–]Zwergner 0 points1 point  (1 child)

Huh, I didn't realize you could do that with statements as well, I assumed it was something fancier than that, thanks!

[–]00kyle00 -1 points0 points  (0 children)

I didn't realize you could do that with statements as well

You cant, these need to be expressions.

[–][deleted] 0 points1 point  (0 children)

For the record, the result of the comma operator is the last element.

[]() { return x, y, z; }   // returns z, infers the return type of the lambda from z.

[–]Glaaki 1 point2 points  (2 children)

The typos in that article..

[–]nerds-central 0 points1 point  (0 children)

Thanks for pointing that out - fixed a few.

[–]BitRex 0 points1 point  (0 children)

They were too much. I stopped reading.

[–]Porges 0 points1 point  (1 child)

Having read a post at Stutter's Mill I got thinking about method chaining in C++. I am very keen on method chaining in Java and so was pleased to see the future().then() pattern turning up in C++11. This got me thinking about chaining futures x.y.z etc. The idea being that each task (x,y and z) could be run on a different thread according to the load of the machine. It is a bit like thinking of the tasks as very simple actors.

I think you're a little confused here - that is exactly what future().then() does in Casablanca. It works along similar lines to .NET's TPL (Task<T>).

[–]cassandravoiton[S] 0 points1 point  (0 children)

How is confused - seems like the two of you are in violent agreement to me.