N4352-53: Parallelism TS Working Draft and Editor's Report - Jared Hoberock

Add a Comment

Comments are closed.

Comments (1)

0 0

Mantosh Kumar said on Jan 22, 2015 07:44 PM:

I just now completed the complete reading of this paper. Looking forward for its inclusion in the standard. However there is minor suggestion in the following sample code which has been used in the examples section.

We should be using "std::lock_guard" in our example as it is the idiomatic way of using "std::mutex" as it is based on RAII concept. This might be useful for future reader who would refer these technical paper.

Kindly ignore in case it was done with some purpose.

Original
--------

using namespace std::experimental::parallel;
int x=0;
std::mutex m;
int a[] = {1,2};
for_each(par, std::begin(a), std::end(a), [&](int) {
m.lock();
++x;
m.unlock();
});


Suggested
---------

using namespace std::experimental::parallel;
int x=0;
std::mutex m;
int a[] = {1,2};
for_each(par, std::begin(a), std::end(a), [&](int) {
std::lock_guard<std::mutex> guard(m);
++x;
});