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.

Task_disable and HWI

Hi all,

I have a simple data structure (stack implementation) and two or more tasks will use this stack in my system. They have different priorities and I need a synchronization mechanism. The first one come into my mind is semaphores, but I am thinking on alternatives. Therefore, I planned to use Task_disable/enable in order to protect critical sections between tasks. However, I have a scenario in my mind which is blurry for me if it is possible to happen.

Ex:

Assume that Task1 calls Task_disable and enters the critical section.

Then, Task2 (a higher priority task) wants to do something with stack, but have to wait for Task1 due to disabled task scheduler.

Before Task1 calling Task_enable() or even completing its task, a HWI preempts this task (Task1).

HWI completes its task and then returns to the task stack.

At that point which task will start? Task1 (which was running before the HWI), or Task2 (which has a higher priority)?

 

I looked at the source code in Task.c and Hwi.c and it seems that Task1 should be started in that case, but I am not sure. Moreover, is it the when a preempting thing is a SWI instead of HWI. Is it safe to use such a mechanism (Task_disable/enable) between tasks with different priorities?

 

Regards

 

SYS/BIOS 6.32.04.49 on EVM6678

  • Hi Deniz Kocak,

    Deniz Kocak said:

    Assume that Task1 calls Task_disable and enters the critical section.

    Then, Task2 (a higher priority task) wants to do something with stack, but have to wait for Task1 due to disabled task scheduler.

    Before Task1 calling Task_enable() or even completing its task, a HWI preempts this task (Task1).

    HWI completes its task and then returns to the task stack.

    At that point which task will start? Task1 (which was running before the HWI), or Task2 (which has a higher priority)?

    Task 1 will run again.  Because you called Task_disable() from within Task 1, no other task in the system can run until Task 1 calls the Task_enable() function.

    Deniz Kocak said:
    Is it safe to use such a mechanism (Task_disable/enable) between tasks with different priorities?

    It is safe as long as you do not have any code that could potentially block forever inside of your critical section of your task. This would potentially starve all other tasks in your application.

    Steve