Skip to content

Fix race in POSIX port vPortEndScheduler #1262

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

Merged
merged 2 commits into from
Apr 3, 2025

Conversation

arctic-alpaca
Copy link
Contributor

Description

Hi, after upgrading from V11.1.0 to V11.2.0, we saw the call to vPortEndScheduler sometimes return when using the POSIX port. We are only calling vPortEndScheduler from FreeRTOS tasks (threads in the POSIX port), so we don't expect the call to actually return.

There seems to be a race between the check whether the thread calling vPortEndScheduler is a FreeRTOS thread and the destruction of the thread key. If the thread key is destroyed before the check, the check fails even for FreeRTOS threads.

Moving the check before the signal to end the scheduler should prevent the race.

Test Steps

Checklist:

  • I have tested my changes. No regression in existing tests.
  • 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.

The `vPortEndScheduler` checks whether it's a FreeRTOS thread after signalling the scheduler thread to stop. This creates a race between the check and the destruction of the thread key. By moving the signal to the scheduler thread after the check, the race is prevented.
@arctic-alpaca arctic-alpaca requested a review from a team as a code owner April 2, 2025 11:47
Signed-off-by: Gaurav Aggarwal <[email protected]>
Copy link

sonarqubecloud bot commented Apr 3, 2025

@rohitmadan07 rohitmadan07 merged commit 03db672 into FreeRTOS:main Apr 3, 2025
17 checks passed
@arctic-alpaca arctic-alpaca deleted the race branch April 7, 2025 06:34
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.

4 participants