summaryrefslogtreecommitdiff
path: root/common_smp/src/tx_thread_delete.c
diff options
context:
space:
mode:
Diffstat (limited to 'common_smp/src/tx_thread_delete.c')
-rw-r--r--common_smp/src/tx_thread_delete.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/common_smp/src/tx_thread_delete.c b/common_smp/src/tx_thread_delete.c
index 510f6565..5bbb12c3 100644
--- a/common_smp/src/tx_thread_delete.c
+++ b/common_smp/src/tx_thread_delete.c
@@ -9,6 +9,8 @@
* SPDX-License-Identifier: MIT
**************************************************************************/
+// Portions of this file were generated with AI assistance.
+
/**************************************************************************/
/**************************************************************************/
@@ -95,6 +97,31 @@ UINT status;
}
}
+ /* The state is terminal, but a terminal state on its own is not authorization to
+ release the control block. Both paths that produce one -- thread completion in
+ _tx_thread_shell_entry and thread termination in _tx_thread_terminate -- publish
+ TX_COMPLETED or TX_TERMINATED, and then run this thread's exit notification
+ callback, before the thread has been detached from the ready list and before
+ those services have finished with the pointer they hold to it. The suspending
+ flag is set for exactly that interval, so a thread whose flag is still set is
+ part-way through the transition. */
+ if (status == TX_SUCCESS)
+ {
+
+ /* Is the completion or termination transition still in progress? */
+ if (thread_ptr -> tx_thread_suspending == TX_TRUE)
+ {
+
+ /* Restore interrupts. */
+ TX_RESTORE
+
+ /* Yes, refuse the delete rather than unlink a thread the scheduler is
+ still holding. The condition is transient: the caller may retry once
+ the transition has finished. */
+ status = TX_DELETE_ERROR;
+ }
+ }
+
/* Determine if the delete operation is okay. */
if (status == TX_SUCCESS)
{