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.82k stars 774 forks source link

Deadlock with threadx linux port #296

Closed akashjjohnWs closed 10 months ago

akashjjohnWs commented 11 months ago

Describe the bug Deadlock when running threadx application with linux port. A lower priority thread gets suspended while holding an internal glibc lock. A higher priority thread gets stuck waiting for this lock which it never gets. Seeing this in time functions, printf functions and all.

To Reproduce The issue is very difficult to reproduce. Running a multi-thread threadx application with threads with variying priorities, this issue would pop up. Since the issue is related to the scheduling timing, it might take a long time for this issue to pop up. Steps to reproduce the behavior:

  1. Clone threadx source.
  2. Configure to build for linux gnu(cmake -Bbuild -G"Unix Makefiles" -DTHREADX_ARCH=linux -DTHREADX_TOOLCHAIN=gnu ./) and build library.
  3. Build a threadx application(A few threads with different priorities printing something to stdout and using the linux time APIs) linking the library.
  4. Run the binary.

Expected behavior The lower priority thread should be able to complete its operation and release the lock.

TiejunMS commented 10 months ago

ThreadX for Linux is for simulation purpose. Not all native Linux resources are managed by ThreadX. The glibc lock is out of the management of ThreadX. To avoid such deadlock, please try to create a ThreadX mutex to synchronize the usage of printf. Whenever printf is invoked, protect it with ThreadX mutex.