VS11 Beta: mixing PPL and C++11 concurrency
-
samedi 3 mars 2012 22:17
Hi,
Is it safe (from the C++ runtime point of view) to mix PPL and C++11 concurrency constructs ? for example:
#include <vector> #include <future> #include <ppl.h> #include <amp_graphics.h> // for float_3 using namespace concurrency; using namespace concurrency::graphics; // CODE..... std::vector<float_3> vInf(16777216); // omitted code for vInf initialization // Reduce asynchronously vInf std::future<float_3> min_future = std::async(std::launch::async, [&] // from C++11 { return parallel_reduce(vInf.begin(), vInf.end(), float_3(FLT_MAX), [](const float_3& a, const float_3& b) // from PPL { return float_3(min(a.x, b.x), min(a.y, b.y), min(a.z, b.z)); }); }); // CODE..... float_3 min_ = min_future.get();
Does the runtime allocate common concurrency resources (threads, sync objects, etc.) for PPL and C++11 ? If not, how does arbitration occur ? What about debugging such code (parallel tasks window in VS) ?
All the best, Arnaud.
Toutes les réponses
-
dimanche 4 mars 2012 07:26Propriétaire
Hi Arnaud,
Thanks for the good question. Yes, it is perfectly safe and in fact intentionally designed to work well when composing these constructs. std::future is powered by PPL Tasks under the hood, and all the sync objects (std::mutex, critical section, conditional variable etc.) are ConcRT aware in the sense that the underlying runtime reacts to the blocking call by scheduling pending tasks.
All futures show up as Tasks in the parallel tasks view window - which is the desired experience for parallel developers.
I touch upon this briefly in my "what's new in VS 11 post" http://blogs.msdn.com/b/nativeconcurrency/archive/2012/02/28/ppl-and-concrt-what-s-new-in-visual-studio-11-beta.aspx
For more on PPL tasks, see this MSDN magazine article: http://msdn.microsoft.com/en-us/magazine/hh781020.aspx
Rahul V. Patil
- Proposé comme réponse DanielMothMicrosoft Employee, Owner dimanche 4 mars 2012 07:51
- Marqué comme réponse Arnaud Faucher dimanche 4 mars 2012 12:42

