bugfix due to capturing of thread index by reference

This commit is contained in:
Matthias Hochsteger 2016-02-23 11:08:20 +01:00
parent 1b4f596446
commit 402e85cc17

View File

@ -195,10 +195,10 @@ void ParallelFor( int first, int next, const TFunc & f )
thread * threads = new thread[nthreads]; thread * threads = new thread[nthreads];
for (int i=0; i<nthreads; i++) for (int i=0; i<nthreads; i++)
{ {
threads[i] = std::thread( [&] () int myfirst = first + (next-first)*i/nthreads;
int mynext = first + (next-first)*(i+1)/nthreads;
threads[i] = std::thread( [myfirst,mynext,&f] ()
{ {
int myfirst = first + (next-first)*i/nthreads;
int mynext = first + (next-first)*(i+1)/nthreads;
f(myfirst, mynext); f(myfirst, mynext);
}); });
} }