title: C++ Parallel Loop without locking critical section using PPL
body: <p>in the below code, there is parallel_for loop implemented with PPL. The main problem is here; abc vector values is not correct when i was commented cs.lock() and cs.unlock(). I am using  concurrency_vector type for randomly access array values but it seems not working. Locking critical section, it's working but slow. Also, for speed up, i used indexing for storing values, not used 2D-concurrency_vector. What is the problem, without locking critical section, what i missed?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;ppl.h&gt;
  
  using namespace concurrency;
  using namespace std;
  
  int test_function()
  {
      critical_section cs;
  
      concurrent_vector&lt; double &gt; abc( 300 * 400, 1000 );
  
      parallel_for ( 0, 1000, [ &amp; ]( int k ) {
          for ( int y = 0; y &lt; 300; y++ ) {
              for ( int x = 0; x &lt; 400; x++ ) {
  
                  /// k is using with some calculations for thr
  
                  cs.lock();
  
                  if ( thr &lt; abc[ 400 * y + x ] ) {
  
                      abc[ 400 * y + x ] = thr;
                  }
  
                  cs.unlock();
              }
          }
      } );
  }
  </code></pre>