This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/TMS320C6678: CSL_semAcquireDirect deadlock

Part Number: TMS320C6678
Other Parts Discussed in Thread: SYSBIOS

Tool/software: TI-RTOS

Hello

Suppose two cores running simultanously on C6678 and accessing a shared variable  in MSMC

On core0 runs task_A

task_A
{
while ((CSL_semAcquireDirect (HW_SEM )) == 0);
..read/write shared var
CSL_semReleaseSemaphore(HW_SEM);
}

On core1 runs task_B

task_B
{
while ((CSL_semAcquireDirect (HW_SEM)) == 0);
..read/write shared var
CSL_semReleaseSemaphore(HW_SEM);
}

so far so good. Now let's add another task to core1, says task_C; also task_C accesses the shared variable

task_C
{
while ((CSL_semAcquireDirect (HW_SEM)) == 0);
..read/write shared var
CSL_semReleaseSemaphore(HW_SEM);
}

Can this cause deadlock? For example, say that Task_C has lower priority than Task_B. The following sequence cause deadlock:

1) Task_C calls CSL_semAcquireDirect and gets  HW_SEM
2) Before Task_C can call CSL_semReleaseSemaphore, Scheduler switches to Task_B (HIGH priority)
3) Task_B spins indefinitely in the while loop
4) Task_C cannot release HW_SEM (LOW priority) ----> deadlock

5) Task_A spins indefinitely 


how to avoid this situation ?

Hope my question is clear
Thank you