The difference between the two specified functions, omp_init_lock_with_hint()
and omp_init_nest_lock_with_hint()
is that it initializes a simple lock and this initializes a nested lock.
The difference between the two (apart from the obvious that one receives a omp_lock_t *
and the other a omp_nest_lock_t *
) is that a task that obtains a simple lock via omp_set_lock()
can not call % with% on same lock without first releasing it using omp_set_lock()
, #
Other OpenMP tasks can call omp_unset_lock()
on a lock already belonging to a different task; they will lock until the task that is currently the owner of the lock releases it using omp_set_lock()
(and the other tasks in front of the queue waiting for the lock also get and release the lock).
Already for a omp_unset_lock()
, if the task owner of the lock calls omp_nest_lock_t
on it, it will merely increment an internal counter, and when calling omp_set_nest_lock()
this counter will be decremented. If the counter value reaches zero, the lock is released. In other words, although the omp_unset_nest_lock()
call on a task-bound lock does not cause deadlock , the task has to issue as many omp_set_nest_lock()
as it issued omp_unset_nest_lock()
before the lock is released. p>
As for the usage examples, I will need some time to restore my knowledge in OpenMP, but the general idea is that, with the simple lock, each task gets the lock with omp_set_nest_lock()
, perform the synchronous and infallible operations (do not raise exceptions) in the critical region, and then release the lock with omp_set_lock()
. In the case of nested_lock, the task can do more complex things, such as getting the lock with omp_unset_lock()
, waiting for an event, and calling omp_set_nest_lock()
on a callback .