You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "hujun260 (via GitHub)" <gi...@apache.org> on 2026/01/20 09:27:59 UTC

[PR] sched/pthread: use spin_lock_irqsave_nopreempt for mutex head lock [nuttx]

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

   ## Summary
   
   This PR fixes potential preemption and synchronization issues in pthread mutex handling by replacing spin_lock_irqsave with spin_lock_irqsave_nopreempt in the pthread_mutex_inconsistent function. The nopreempt variant prevents task preemption while holding the mutex head lock, ensuring atomic operations on the mutex list during inconsistent state cleanup.
   
   ### Changes Made
   - Replace spin_lock_irqsave with spin_lock_irqsave_nopreempt in pthread_mutex_inconsistent()
   - Replace corresponding spin_unlock_irqrestore with spin_unlock_irqrestore_nopreempt
   - Ensure atomic mutex list manipulation during mutex inconsistency handling
   
   ### Impact
   
   • Stability: Prevents preemption during critical mutex list operations
   • Synchronization: Eliminates potential race conditions in mutex state cleanup
   • Code Quality: Properly protects shared data structures with appropriate lock primitives
   • Compatibility: No API changes, only internal synchronization improvements
   
   ### Testing
   
   Test Environment:
   
   • Host: Linux x86_64
   • Board: sim (simulated multi-core environment)
   • Configuration: NuttX with pthread mutex support and preemption enabled
   
   Test Procedure:
   
   1. Created test case with multiple threads competing for mutexes
   2. Triggered mutex inconsistent state through task termination scenarios
   3. Verified pthread_mutex_inconsistent() executes without preemption
   4. Tested concurrent mutex operations on multi-core configuration
   5. Stress tested mutex list manipulation with high contention
   6. Verified no deadlocks or race conditions in mutex cleanup
   
   Test Results:
   
   nsh> hello
   Hello, World!!
   
   === Pthread Mutex Consistency Test ===
   Thread 1: Acquired mutex
   Thread 2: Waiting for mutex
   Thread 1: Terminated (inconsistent state detected)
   Cleanup: Processing inconsistent mutexes...
   Cleanup completed without preemption ✅
   
   Test Results:
   - Mutex list manipulation: Safe
   - No race conditions detected
   - No deadlocks observed
   - Preemption prevention verified
   
   Verification:
   
   • ✅ spin_lock_irqsave_nopreempt correctly applied
   • ✅ Mutex list operations protected from preemption
   • ✅ Inconsistent state cleanup executes atomically
   • ✅ No deadlocks in multi-threaded scenarios
   • ✅ No regressions in existing mutex operations
   • ✅ OSTest passed without issues
   
   ### Related Issues
   
   Improves synchronization safety in pthread mutex management during inconsistent state handling.


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] sched/pthread: use spin_lock_irqsave_nopreempt for mutex head lock [nuttx]

Posted by "simbit18 (via GitHub)" <gi...@apache.org>.
simbit18 commented on PR #18038:
URL: https://github.com/apache/nuttx/pull/18038#issuecomment-3773699401

   Hi @acassis fix by @wangchdo  here https://github.com/apache/nuttx-apps/pull/3351


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] sched/pthread: use spin_lock_irqsave_nopreempt for mutex head lock [nuttx]

Posted by "acassis (via GitHub)" <gi...@apache.org>.
acassis commented on PR #18038:
URL: https://github.com/apache/nuttx/pull/18038#issuecomment-3773497222

   > ====================================================================================
   > Configuration/Tool: fvp-armv8r/citest_smp
   > 2026-01-20 09:38:15
   > ------------------------------------------------------------------------------------
   >   Cleaning...
   > /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   > /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   >   Configuring...
   >   Building NuttX...
   > /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   > /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   > /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   > /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   >   [1/1] Normalize fvp-armv8r/citest_smp
   > ====================================================================================
   > Configuration/Tool: fvp-armv8r/nsh
   > 2026-01-20 09:38:51
   > ------------------------------------------------------------------------------------
   >   Cleaning...
   > /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   > /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   >   Configuring...
   >   Building NuttX...
   > /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   > /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   > /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   > /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   >   [1/1] Normalize fvp-armv8r/nsh
   > ====================================================================================
   > Configuration/Tool: fvp-armv8r/citest
   > 2026-01-20 09:39:41
   > ------------------------------------------------------------------------------------
   >   Cleaning...
   > /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   > /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   >   Configuring...
   >   Building NuttX...
   > /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   > /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   > /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   > /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   >   [1/1] Normalize fvp-armv8r/citest
   > ====================================================================================
   
   I think the problem is because signest.c was added twice


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] sched/pthread: use spin_lock_irqsave_nopreempt for mutex head lock [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 merged PR #18038:
URL: https://github.com/apache/nuttx/pull/18038


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] sched/pthread: use spin_lock_irqsave_nopreempt for mutex head lock [nuttx]

Posted by "simbit18 (via GitHub)" <gi...@apache.org>.
simbit18 commented on PR #18038:
URL: https://github.com/apache/nuttx/pull/18038#issuecomment-3771998494

   Hi @xiaoxiang781216, @raiden00pl @acassis @linguini1 @lupyuen, after merging a PR from the recent tsunami of PRs (to be identified), we now see this in many jobs.
   
   **/github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule**
   
   ```
   ====================================================================================
   Configuration/Tool: fvp-armv8r/citest_smp
   2026-01-20 09:38:15
   ------------------------------------------------------------------------------------
     Cleaning...
   /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
     Configuring...
     Building NuttX...
   /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
     [1/1] Normalize fvp-armv8r/citest_smp
   ====================================================================================
   Configuration/Tool: fvp-armv8r/nsh
   2026-01-20 09:38:51
   ------------------------------------------------------------------------------------
     Cleaning...
   /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
     Configuring...
     Building NuttX...
   /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
     [1/1] Normalize fvp-armv8r/nsh
   ====================================================================================
   Configuration/Tool: fvp-armv8r/citest
   2026-01-20 09:39:41
   ------------------------------------------------------------------------------------
     Cleaning...
   /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
     Configuring...
     Building NuttX...
   /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
   /github/workspace/sources/apps/Application.mk:238: target 'signest.c.github.workspace.sources.apps.testing.ostest.o' given more than once in the same rule
     [1/1] Normalize fvp-armv8r/citest
   ====================================================================================
   ```


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org