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.

BIOS 6: Task_delete behaviour

Other Parts Discussed in Thread: SYSBIOS

hi,


I am using BIOS bios_6_21_02_19


I have task which waits on a semaphore.
When I need to shutdown my system, I need to delete the task.
However when I use task delete its says "cannot delete blocked or running task"
As such I can ensure that task is not running and is instead blocked on the semaphore.
From a logical perspective it ok to delete the task now, but BIOS 6 API gives above error in CCS console 
So I apply a workaround like below.
However I would prefer to not have such a workaround.
Let me know whats the typical logic followed when deleting a task in BIOS 6.


regards
Kedar

// work around to delete a task

Bool doExit;

Void my_Task_main() // for my_Task_Hndl
{
   doExit = 0;
   while(1)
   {

       Semaphore_pend(&someEvent, BIOS_WAIT_FOREVER);
       if(doExit)
           break; // exit task

        // do some work based on event

}


my_Task_delete() // called for some other task context
{
   doExit = 1;
   Task_sleep(1); // wait for task to get exited
   Task_delete(&my_task_Hndl);
}

  • Kedar --

    There's already a bug filed asking that we allow tasks that are in "blocked" state to be deleted.  SDOCM00046393. I'm not sure if we'll get to it in 6.30.

    Problems still remain in that you need to tell "someone else" to delete you.  One way to do this is to put yourself on a queue and signal another thread.

    The below sample app shows a neat way to handle this (thanks to Brad Caldwell who showed me this trick several years ago)

    Create a mailbox to hold task handle.  Make it size 1.

    Create a low priority "cleanup" task.  This cleanup task will call Mailbox_pend and wait for a task handle.

    Before a task exits, it calls Mailbox_post() to send the task handle to the cleanup task.

    If more than one task wants to exit, those tasks will block waiting for the cleanup task to run.  You can increase the mailbox size if you don't like the extra context switches, but this works out pretty cleanly with '1'.

    Regards,
    -Karl-

     

    ----------------------------------- C code ------------------------------------


    #include <xdc/std.h>
    #include <xdc/runtime/System.h>

    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Task.h>
    #include <ti/sysbios/ipc/Mailbox.h>


    Mailbox_Handle taskDeleteMailbox;
    Void taskDeleteTask(UArg arg0, UArg arg1);

    /*
     *  ======== taskDeleteTask ========
     */
    void taskDeleteTask(UArg a0, UArg a1)
    {
        Task_Handle taskHandle;
       
        System_printf("taskDeleteTask: started.\n");
       
        for (;;) {
            Mailbox_pend(taskDeleteMailbox, &taskHandle, BIOS_WAIT_FOREVER);
           
            System_printf("deleting 0x%08x\n", taskHandle);
           
            Task_delete(&taskHandle);
        }
    }

    /*
     *  ======== task ========
     */
    void task(UArg a0, UArg a1)
    {
        Task_Handle self = Task_self();
       
        System_printf("task 0x%08x = %d\n", Task_self(), a0);
       
        /* send message to the (low priority) cleanup task to tell it to delete me */
        Mailbox_post(taskDeleteMailbox, &self, BIOS_WAIT_FOREVER);
    }

    /*
     *  ======== main ========
     */
    Void main()
    {
        Task_Params taskParams;
        Int i;
     
        taskDeleteMailbox = Mailbox_create(sizeof(Task_Handle), 1, NULL, NULL);
       
        Task_Params_init(&taskParams);
        taskParams.priority = 1;        // minimum priority
        Task_create(taskDeleteTask, &taskParams, NULL);
       
        for (i=0; i < 3; i++) {
            Task_Params_init(&taskParams);
            taskParams.priority = 5;
            taskParams.arg0 = i;
            Task_create(task, &taskParams, NULL);
        }

        BIOS_start();
    }

    ------------------------------------ .cfg code -------------------------------------------

     

     
    var Memory = xdc.useModule('xdc.runtime.Memory');
    var BIOS = xdc.useModule('ti.sysbios.BIOS');
    var Task = xdc.useModule('ti.sysbios.knl.Task');
    var Mailbox = xdc.useModule('ti.sysbios.ipc.Mailbox');
    var HeapMem = xdc.useModule('ti.sysbios.heaps.HeapMem');

    var System = xdc.useModule('xdc.runtime.System');
    var SysStd = xdc.useModule('xdc.runtime.SysStd');
    System.SupportProxy = SysStd;

    /* Create default heap and hook it into Memory */
    var heapMemParams = new HeapMem.Params;
    heapMemParams.size = 0x8000;
    var heap0 = HeapMem.create(heapMemParams);

    Memory.defaultHeapInstance = heap0;

     

     

    -------------------------------- sample output -----------------------

     

    task 0xc00122a8 = 0
    task 0xc0012b00 = 1
    task 0xc0013358 = 2
    taskDeleteTask: started.
    deleting 0xc00122a8
    deleting 0xc0012b00
    deleting 0xc0013358