Purpose
The omp_test_lock function attempts to set the lock associated with the specified lock variable. It returns .TRUE. if it was able to set the lock and .FALSE. otherwise. In either case, the calling thread will continue to execute subsequent instructions in the program.
If you call omp_test_lock with an uninitialized lock variable, the result of the call is undefined.
Class
Function.
Argument Type and Attributes
Result Type and Attributes
Default logical.
Result Value
.TRUE. if the function was able to set the lock. .FALSE. otherwise.
Examples
In the following example, a thread repeatedly executes WORK_A until it can set the lock variable, LCK. When the lock variable is set, the thread executes WORK_B.
USE omp_lib INTEGER LCK INTEGER ID CALL omp_init_lock (LCK) !$OMP PARALLEL SHARED(LCK), PRIVATE(ID) ID = omp_get_thread_num() DO WHILE (.NOT. omp_test_lock(LCK)) CALL WORK_A (ID) END DO CALL WORK_B (ID) CALL omp_unset_lock (LCK) !$OMP END PARALLEL CALL omp_destroy_lock (LCK)