Purpose
This subroutine causes the executing thread to release ownership of the specified lock. The lock can then be set by another thread as required. The behavior of the omp_unset_lock subroutine is undefined if either of the following conditions occur:
Class
Subroutine.
Argument Type and Attributes
Result Type and Attributes
None.
Result Value
None.
Examples
USE omp_lib INTEGER A(100) INTEGER(kind=omp_lock_kind) LCK_X CALL omp_init_lock (LCK_X) !$OMP PARALLEL PRIVATE (I), SHARED (A, X) !$OMP DO DO I = 3, 100 A(I) = I * 10 CALL omp_set_lock (LCK_X) X = X + A(I) CALL omp_unset_lock (LCK_X) END DO !$OMP END DO !$OMP END PARALLEL CALL omp_destroy_lock (LCK_X)
In this example, the lock variable LCK_X is used to avoid race conditions
when updating the shared variable X. By setting the lock before each
update to X and unsetting it after the update, you ensure that only one thread
is updating X at a given time.