Partager via


omp_test_lock

Essaie de définir un verrou mais ne bloque pas l'exécution des threads.

int omp_test_lock(
   omp_lock_t *lock
);

Notes

où,

Notes

Pour plus d'informations, consultez 3.2.5 Fonctions omp_test_lock and omp_test_nest_lock.

Exemple

// omp_test_lock.cpp
// compile with: /openmp
#include <stdio.h>
#include <omp.h>
                    
omp_lock_t simple_lock;                 
                    
int main() {
    omp_init_lock(&simple_lock);
                    
    #pragma omp parallel num_threads(4)
    {
        int tid = omp_get_thread_num();

        while (!omp_test_lock(&simple_lock))
            printf_s("Thread %d - failed to acquire simple_lock\n",
                     tid);
                    
        printf_s("Thread %d - acquired simple_lock\n", tid);
                       
        printf_s("Thread %d - released simple_lock\n", tid);
        omp_unset_lock(&simple_lock);
    }
                    
    omp_destroy_lock(&simple_lock);
}
  

Voir aussi

Concepts

Fonctions OpenMP