Menu

#16 Task specific callback for resource cleanup.

open
nobody
None
5
2020-02-25
2007-10-29
No

The idea is to extend the semantic of the vTaskDelete function in order to give a task a change to release task specific resource before it is deleted.

A task can use an API function like the following to notify the kernel about its callback:

vTaskSetCallback(Event callbackType, xTaskHandle task, func *pCallback)

callbackType - specifies the callback is setting (to be used for further extension).

task - specifies the task identifier.

pCallback - specifies the pointer to some defined function type.

Discussion

  • Stefano Oliveri

    Stefano Oliveri - 2007-10-29

    Sequence Diagram

     
  • Stefano Oliveri

    Stefano Oliveri - 2007-10-29

    Logged In: YES
    user_id=1924273
    Originator: YES

    Regards,
    Stefano

     
  • Hein Tibosch

    Hein Tibosch - 2020-02-25

    Although this is a very old proposal, I'd like to respond to it.

    The biggest problem with the proposed solution is that the function pointed to by pCallback will be called ( executed ) from either a different task or worse, from the idle task. Note that no guarantees can be given about the available stack space, the current task priority, or task specific privileges.

    When task-A terminates, its termination code should be better executed from the task-A context. This means that also vTaskDelete() will be called by task to be deleted.

    So why not send a message to task-A that says "please terminate"? The task can first finish any important action, release mutexes / resources, and then call its own termination code. The final thing to do is call vTaskDelete().

    void vMyTask( void * pvParameter )
    {
        while( !has_to_stop )
        {
            /* Do the work. */
        }
        my_exit_code();
    
        vTaskDelete( NULL );
    }
    

    For C++ users: this solution also allows to declare objects that have destructors:

    void vMyTask( void * pvParameter )
    {
        {
            CClass some_object;
    
            while( !has_to_stop )
            {
                /* Do the work. */
            }
            /* CClass::~CClass (destructor) will be executed. */
        }
        my_exit_code();
    
        vTaskDelete( NULL );
    }
    

    As for this feature request: I recommend closing it after 13 years.

     

Log in to post a comment.