We recommend using Visual Studio 2017
This documentation is archived and is not being maintained.

A.31 Thread-Safe Lock Functions

The following C++ example demonstrates how to initialize an array of locks in a parallel region by using omp_init_lock (Section 3.2.1 on page 42).


// A_13_omp_init_lock.cpp
// compile with: /openmp
#include <omp.h>

omp_lock_t *new_locks() {
   int i;
   omp_lock_t *lock = new omp_lock_t[1000];
   #pragma omp parallel for private(i)
   for (i = 0 ; i < 1000 ; i++)

   return lock;

int main () {}