omp_init_lock
initialise un verrou simple.
void omp_init_lock(
omp_lock_t *lock
);
Paramètres
- lock
une variable de type omp_lock_t.
Notes
Pour plus d'informations, consultez 3.2.1 Fonctions omp_init_lock and omp_init_nest_lock.
Exemple
// omp_init_lock.cpp
// compile with: /openmp
#include <stdio.h>
#include <omp.h>
omp_lock_t my_lock;
int main() {
omp_init_lock(&my_lock);
#pragma omp parallel num_threads(4)
{
int tid = omp_get_thread_num( );
int i, j;
for (i = 0; i < 5; ++i) {
omp_set_lock(&my_lock);
printf_s("Thread %d - starting locked region\n", tid);
printf_s("Thread %d - ending locked region\n", tid);
omp_unset_lock(&my_lock);
}
}
omp_destroy_lock(&my_lock);
}