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

Spurious wakeups on semaphores #53

Open
dns13 opened this issue Aug 7, 2023 · 2 comments
Open

Spurious wakeups on semaphores #53

dns13 opened this issue Aug 7, 2023 · 2 comments
Assignees

Comments

@dns13
Copy link

dns13 commented Aug 7, 2023

In your ReadWriteLock you should check the return values of your xSemaphoreTake() calls to be prone against spurious wakeups. For example if you call vTaskAbortDelay() to wake up a sleeping task from another, it will also cancel your waits on the semaphore. Unfortunately that behaviour is not really documented, but I've ran into it - took me a while.

I do it like so

while (xSemaphoreTake(sem, portMAX_DELAY) != pdTRUE) {}
@michaelbecker michaelbecker self-assigned this Aug 25, 2023
@dns13
Copy link
Author

dns13 commented Dec 18, 2023

Seems to be fixed with FreeRTOS v11.0.0:

  • Prevent tasks waiting for a notification from being resumed by calls to
    vTaskResume or vTaskResumeFromISR. We thank @Moral-Hao for their
    contribution.

@Moral-Hao
Copy link

Hi, @dns13 , I don't think the change I made could fix the problem you described.
Before my change, a task waiting for a notification with portMAX_DELAY may be identified as suspended, and this task could be woke up by vTaskResume. After my change, this task could not be woke up by vTaskResume.
A task waiting for something(semaphore/event/notify) with portMAX_DELAY still could be woke up by xTaskAbortDelay.

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

No branches or pull requests

3 participants