AnsweredAssumed Answered

A general question about locks

Question asked by vix on Jul 24, 2014
Latest reply on Aug 12, 2014 by CraigG

I've been using VDSP++ 5.0.10 and 5.1.0 and I need to sync the access to SPI peripheral between two different thread (in a VDK project).

For this reason I use locks, through function adi_acquire_lock(), adi_try_lock() and adi_release_lock().

Is this the best approach to avoid concurrent usage of the saem resource (SPI peripheral)?

 

During the developent I see something that I can't explain:

I read in the VDSP++ help:

The functions operate on a pointer to a testset_t object, which is a private type used only by these routines. Objects of type testset_t must be global, and initialized to zero (which indicates that the lock is unclaimed). The type is automatically volatile.

But I noticed that after a successfull call to adi_acquire_lock(lockptr) or adi_try_lock(lockptr), the testset_t object is always zero.

And I can successfully call adi_acquire_lock(lockptr) or adi_try_lock(lockptr) once again on the same lock.

I mean:

while (!adi_try_lock(lockptr)) {

// do someting else or go to sleep

// before trying the lock again

}

while (!adi_try_lock(lockptr)) {

// do someting else or go to sleep

// before trying the lock again

}

 

Is this an expected behavior?

In my application I have some problems and I think the problem is a concurrent access to the SPI (even if I use lock).

Outcomes