Skip to content

Delete task outside of critical section to avoid malloc mutex deadlock#4

Open
scott-brust wants to merge 1 commit into
particlefrom
fix/delete-task-outside-critical-section
Open

Delete task outside of critical section to avoid malloc mutex deadlock#4
scott-brust wants to merge 1 commit into
particlefrom
fix/delete-task-outside-critical-section

Conversation

@scott-brust

Copy link
Copy Markdown
Member

During USB de-initialization, the realtek SDK will delete its internal USB Freertos task. This process involves freeing malloc'd memory. Our heap implementation is protected by a mutex, which can be unavailable if another task holds the mutex.
The default implementation of vTaskDelete() in freertos deletes all tasks under a critical section, ie with interrupts disabled.
If we call vTaskDelete() while another task holds the malloc mutex, we will deadlock as interrupts are disabled.
This PR moves the actual tcb deletion / freeing outside of the critical section in order to avoid deadlocks on this mutex.

See original discussion here

Credit to @avtolstoy for the fix.

@scott-brust scott-brust requested a review from avtolstoy April 24, 2023 17:46
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.

2 participants