hujun260 opened a new pull request, #17953:
URL: https://github.com/apache/nuttx/pull/17953

   ## Summary
   
   This PR fixes a regression in task exit handling that causes assertion 
failures 
   in critical section management. The issue occurs during `nxtask_terminate()` 
when 
   the ready-to-run task list state is inconsistent with the running thread, 
leading 
   to improper IRQ count state and assertion failures in 
`enter_critical_section()`.
   
   ## Changes
   
   Reorder operations in `nxtask_exit()` to ensure proper critical section 
state:
   
   1. **sched/task/task_exit.c**:
      - Move `nxsched_switch_context()` call after `TSTATE_TASK_INACTIVE` is set
      - Increment IRQ count before context switch to establish proper state
      - Ensures `enter_critical_section()` doesn't incorrectly try to acquire 
        `g_cpu_irqlock` when `rtcb->irqcount` is zero
      - Maintains proper task state transition sequence during termination
   
   ## Testing
   
   Tested on:
   - **Platform**: NuttX ARM architecture (arm64/armv7/armv8-r)
   - **Configuration**: Multi-threaded applications with concurrent task 
creation/destruction
   - **Method**:
     - Verified task exit no longer triggers assertion failures in 
`irq_csection.c:244`
     - Tested with applications that repeatedly create and terminate multiple 
tasks
     - Verified proper scheduler state transitions during termination
     - Tested error handling paths and concurrent task operations
   - **Result**:
     - No assertion failures observed during task termination
     - Proper scheduler context switching maintained
     - Correct TCB release sequence preserved
     - All task state transitions validated
   
   ## Impact
   
   - **Stability**: Fixes critical assertion failures that block task 
termination
   - **Correctness**: Ensures proper critical section and IRQ count state 
management
   - **Compatibility**: No breaking changes; maintains existing API semantics
   - **Performance**: Minimal overhead; only reorders existing operations
   - **Code Quality**: Improves robustness of task lifecycle management


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to