Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark mutex as robust to prevent deadlocks #1233

Merged
merged 4 commits into from
Jan 29, 2025
Merged

Conversation

aggarg
Copy link
Member

@aggarg aggarg commented Jan 25, 2025

Description

Prevent application hangs that occur when a thread dies while holding a mutex, particularly during vTaskEndScheduler or exit calls. This is achieved by setting the PTHREAD_MUTEX_ROBUST attribute on the mutex.

Test Steps

Tested locally using the modified application as suggested in this thread. Was also tested by @denravonska.

Checklist:

  • I have tested my changes. No regression in existing tests.
  • [NA] I have modified and/or added unit-tests to cover the code changes in this Pull Request.

Related Issue

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Prevent application hangs that occur when a thread dies while holding a
mutex, particularly during vTaskEndScheduler or exit calls. This is
achieved by setting the PTHREAD_MUTEX_ROBUST attribute on the mutex.

Fixes:
- GitHub issue: FreeRTOS#1217
- Forum thread: freertos.org/t/22287

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
Copy link

codecov bot commented Jan 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.53%. Comparing base (31dd1e3) to head (92be5d4).
Report is 17 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1233      +/-   ##
==========================================
- Coverage   91.64%   91.53%   -0.11%     
==========================================
  Files           6        6              
  Lines        3254     3260       +6     
  Branches      903      901       -2     
==========================================
+ Hits         2982     2984       +2     
- Misses        132      135       +3     
- Partials      140      141       +1     
Flag Coverage Δ
unittests 91.53% <ø> (-0.11%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
@denravonska
Copy link

Tested on my end. vTaskEndScheduler no longer deadlocks for me.

@aggarg aggarg merged commit ad4e723 into FreeRTOS:main Jan 29, 2025
17 checks passed
@aggarg aggarg deleted the posix_port branch January 29, 2025 01:57
@@ -46,23 +48,36 @@ struct event * event_create( void )
if( ev != NULL )
{
ev->event_triggered = false;
pthread_mutex_init( &ev->mutex, NULL );
pthread_mutexattr_init( &ev->mutexattr );
#ifndef __APPLE__
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder how we can get similar benefits on macOS/iOS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants