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.

[FAQ] TDA4VH-Q1: Why does a custom application not exit cleanly when Ctrl-C is invoked?

Part Number: TDA4VH-Q1

When a user presses Ctrl-C to stop the application, the default behavior sets a shutdown flag but may not perform proper cleanup. The main application thread could be blocked waiting for messages from the remote cores (R5F, C7x), which are still processing data or holding resources. Since the thread is blocked waiting, the cleanup sequence can not complete the necessary steps to release these resources and shut down properly, resulting in an ungraceful shutdown where communication channels and memory remain allocated. The system can not fully recover unless the device is power cycled or the cores are manual reset, after which the application can run again. The expectation is that the user's application needs to register a working Ctrl-C signal handler to do a graceful shutdown.

How do I implement a working SIGINT handler to my custom application? 

  • To handle Ctrl-C gracefully and ensure proper cleanup of remote core resources, implement a SIGINT handler that sets a shutdown flag and triggers the cleanup sequence. Use the example implemented using the single cam demo found in the vision apps demo below as a reference for your own implementation:

    1. Include signal handler

    #include <signal.h> 

    2. Add signal handler function

    static void app_single_cam_intSigHandler(int sig)
    {
        AppObj *obj = &gAppObj;
    
        /* Set flag to stop the application */
        obj->stop_task = 1;
    
    #if defined(SOC_AM62A) && defined(QNX)
        obj->stop_screen_task = 1;
    #endif
    
        printf("\nReceived Ctrl+C (SIGINT), shutting down gracefully...\n");
    }

    3. Register the signal handler in main(). Recommended to register it early

    int app_single_cam_main(int argc, char* argv[])
    {
        AppObj *obj = &gAppObj;
        vx_status status = VX_FAILURE;
    
        /* Register the signal handler for Ctrl+C */
        signal(SIGINT, app_single_cam_intSigHandler);
        
        /* Continue with initialization... */

    4. Check stop flags in all loops and tasks

    Such as main processing loop:

    for(i=0; i<frm_loop_cnt; i++)
    {
        /*Process frames*/
        
        if((obj->stop_task) || (status != VX_SUCCESS))
        {
            break;
        }
    }

    Interactive menus:

    case 'x':
                        obj->stop_task = 1;
    #if defined(SOC_AM62A) && defined(QNX)
                        obj->stop_screen_task = 1;
    #endif
                        done = 1;
                        break;

    This was was tested on SDK 11.01.00.04 for J784S4 and is the same implementation for the other TDA4 devices (as well as the AM62A)

    Warm regards,

    Christina Kuruvilla