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.

Does TSK_delete() call MEM_free() to free the stack in both cases?

Hi all,

According to DSP/BIOS v5.41 User Guide (SPRU423H) section 4.4.1.1: "TSK_delete removes the task from all internal queues and frees the task object and stack by calling MEM_free." The API reference guide (SPRU403r) p. 2-538 basically says the same thing.

However, the stack can be allocated in two ways: Automatically by assigning TSK_Attrs.stack to NULL, or manually. Does TSK_delete() call MEM_free() in both cases? (Especially since the manual memory allocation/free case then becomes asymmetric.)

All the best,
Fredrik

  • Fredrik,

    TSK_delete only calls MEM_free() in the case TSK_Attrs.stack is NULL during create.  This is the only case in which TSK_create() does a malloc of memory.

    If you pas in a stack during TSK_create(), we cannot call MEM_free() because we don't know from what memory the stack was taken.

    Judah

  • Hi Judah,

    That is what I thought too, at first. However, upon later inspection of the TSK_Attrs struct (please find quoted below), I found that there actually exists a field called "stackseg" (along with "stacksize" and the "stack" pointer itself). So, technically, TSK_delete() should be able to do MEM_free() in both cases, like the manual suggests.

    The question is: Is it a correct interpretation of the manual that MEM_free() actually is called in both cases, and does TSK_delete() actually do that properly?

    C.f. "TMS320C6000 DSP/BIOS 5.x API Reference Guide" (SPRU403r) p. 2-536:

    struct TSK_Attrs { /* task attributes */
            Int priority; /* execution priority */
            Ptr stack; /* pre-allocated stack */
            size_t stacksize; /* stack size in MADUs */
            Int stackseg; /* mem seg for stack alloc */
            Ptr environ; /* global environ data struct */
            String name; /* printable name */
            Bool exitflag; /* prog termination requires */
            /* this task to terminate */
            Bool initstackflag; /* initialize task stack? */
    };

    All the best,
    Fredrik

  • Fredrik,

    How it works is that if you specify the "stack" field then "stackseg" is set to -1 and doesn't come into play.  Only when "stack" is null that we use "stackseg" for allocating the stack.  So, what I said in my previous post still holds true.

    Judah

  • Hi Judah,

    OK, thank you very much. Perhaps the manual could clarify these points and describe the interplay between the stack fields in more detail.

    Many thanks,
    Fredrik

  • Hi Judah,

    Would bios.TSK.DELETEFXN be the proper place to call MEM_free for the stack?

    All the best,
    Fredrik

  • Fredrik,

    Yes, it looks like should be able to do this within the TSK.DELETEFXN.

    Judah