title: FreeRTOS stuck at prvCheckTasksWaitingTermination
body: <p>I'm working with a Nucleo-STm32F767 and I had generated the code with CubeMX including FreeRTOS 9.</p>
  
  <p>My code has 5 task and each task has a loop, where the task is suspended on each iteration.</p>
  
  <pre><code>  while( 1 )
    {   
      //Do something
  
      osDelay(TASK_MAIN_DELAY_MS);
    }
  </code></pre>
  
  <p>At this point my system works well.</p>
  
  <p>Now I added a task that handle the communication with an SPI network controller. The network controller has it own middleware written in C.</p>
  
  <p>Now every time I try to suspend a task (with osDelay) my code is stucked into <strong>prvCheckTasksWaitingTermination</strong> and my system is blocked forever.</p>
  
  <pre><code>static void prvCheckTasksWaitingTermination( void )
  {
  
      /** THIS FUNCTION IS CALLED FROM THE RTOS IDLE TASK **/
  
      #if ( INCLUDE_vTaskDelete == 1 )
      {
          BaseType_t xListIsEmpty;
  
          /* ucTasksDeleted is used to prevent vTaskSuspendAll() being called
          too often in the idle task. */
          while( uxDeletedTasksWaitingCleanUp &gt; ( UBaseType_t ) 0U )
          {
              vTaskSuspendAll();
              {
                  xListIsEmpty = listLIST_IS_EMPTY( &amp;xTasksWaitingTermination );
              }
              ( void ) xTaskResumeAll();
  
              if( xListIsEmpty == pdFALSE )
              {
                  TCB_t *pxTCB;
  
                  taskENTER_CRITICAL();
                  {
                      pxTCB = ( TCB_t * ) listGET_OWNER_OF_HEAD_ENTRY( ( &amp;xTasksWaitingTermination ) );
                      ( void ) uxListRemove( &amp;( pxTCB-&gt;xStateListItem ) );
                      --uxCurrentNumberOfTasks;
                      --uxDeletedTasksWaitingCleanUp;
                  }
                  taskEXIT_CRITICAL();
  
                  prvDeleteTCB( pxTCB );
              }
              else
              {
                  mtCOVERAGE_TEST_MARKER();
              }
          }
      }
      #endif /* INCLUDE_vTaskDelete */
  </code></pre>
  
  <p>In particular, the execution is stopped here: while( uxDeletedTasksWaitingCleanUp > ( UBaseType_t ) 0U ) becuase <strong>uxDeletedTasksWaitingCleanUp</strong> is equal to 0.</p>
  
  <p>I don't know how to resolve this issue :(</p>
  
  <p>Anybody can help me?</p>
  
  <p>Thanks and best regards,
  Federico</p>