On Wed, Mar 29, 2017 at 7:18 AM, Radosław Biernacki <r...@semihalf.com> wrote:
> Hi all,
>
> The documentation for odp_schedule_order_lock(unsigned lock_index) does not
> specify the sequence in which the lock_index need to be given.

That's because there is no such required sequence. Each lock index is
a distinct ordered synchronization point and the only requirement is
that each thread may only use each index at most once per ordered
context. Threads may skip any or all indexes as there is no obligation
for threads to use ordered locks when they are present in the context,
and the index order doesn't matter to ODP.

When threads enter an ordered context they hold a sequence that is
determined by the source ordered queue. For a thread to be able to
acquire ordered lock index i, all that is required is that all threads
holding lower sequences have either acquired and released that index
or else definitively passed on using it by exiting the ordered
context. So if thread A tries to acquire index 1 first and then index
2 while Thread B tries to acquire index 2 first and then index 1 it
doesn't matter since each individual index follows the same order,
which is fixed for both Thread A and B.

Note that there may be a loss of parallelism if indexes are permuted,
however there is no possibility of deadlock. Best parallelism will be
achieved when all threads use indexes in the same sequence, but ODP
doesn't care what sequence of indexes the application chooses to use.

>
> Shouldn't the following statements be included in description of this
> function?
> 1) All code paths calling this function (in the same synchronization
> context) need to use the same lock_index sequence, eg: 1, 3, 2, 4 or the
> results are undefined (like the sequence of events will not be preserved)
> if this rule is not followed
> 2) The doc should emphasize a bit more to what the synchronization context
> is bound to (source queue). For eg. it should say that lock_index sequence
> can be different for different source queues (synchronization contexts).
> 3) It is possible to skip some lock_index in sequence. But skipped
> lock_indexes cannot be used outside of the sequence (since this will alter
> the sequence which is violation of rule 1).

Reply via email to