eclipse-threadx / threadx

Eclipse ThreadX is an advanced real-time operating system (RTOS) designed specifically for deeply embedded applications.
https://github.com/eclipse-threadx/rtos-docs/blob/main/rtos-docs/threadx/index.md
MIT License
2.8k stars 767 forks source link

Unexpected behavior when reclaiming resources after a thread completes on it's own #394

Open ASeidelt opened 2 weeks ago

ASeidelt commented 2 weeks ago

Hi, we want to implement a system that does spawn multiple threads during its lifetime. Some of them are terminated by other threads, most of them exit the entry function after completion. Several threads may be started and stopped multiple times during the life time of the system. We are using ThreadX V6.2.0, target is STM32 ARM.

When reading the documentation and analyzing the behavior of ThreadX with test code we have made the following observations:

Common:

TERMINATE:

COMPLETE:

We now have the following questions:

void fi_init_thread_exit_notify_and_deinit(TX_THREAD *thread, UINT cond)
{
  if(thread && cond==TX_THREAD_EXIT) {
    tx_thread_delete(thread);  // remove thread from list
    tx_byte_release(thread->tx_thread_stack_start); // free stack
  }
}

regards Andre