cancel
Showing results for 
Search instead for 
Did you mean: 

Understanding ThreadX scheduling

MGuth.1
Associate III

Hi all and merry Christmas!

It's Christmas time again and therefore it's time for me specifically to work on my private projects. I want to build up a rather complex device running on ThreadX and just wanted to play around with ThreadX trying to understand it. But I'm struggling even on a simple setup.

The current state of my code is:

- one main thread created from the .ioc file by CubeIDE with priority 10

- 2 user threads coded by myself using same priority (11) etc.One of which is a simply blinky, the other one is sending a string on USART2 interface

- 1 interrupt triggered by an EXTI (Pushbutton) sending a string on USART2 interface

 

Both user threads are designed with a while loop as it was the way given in all examples I found and I also noticed that without the while loop, the entry-function is run once only (of course also with the while loop it is triggered once, but due to the while loop always repeating).

I'm having issues understanding the scheduling of ThreadX I think. I do have basic knowledge about scheduling, Round Robin, FIFO, etc. and I also read across the ThreadX User Guide by Microsoft.
I understood, that the entry-function that is referred in the tx_thread_create() call is called once. That's why you need to insert the while loop to have a continous blinky for example. Several questions I have are:

1. Talking about both user threads, when is one thread interrupted to execute the second one? Is it after running through one while cycle? is it random? is it time based?

2. Having both user threads with the same configuration (priority, etc), I only get the first user thread running. The LED is blinking constantly, the UART-message is not popping up on the serial monitor. The USART2-interface however is working as the interrupt is delivering a message. Also when debugging I never enter user thread 2.

3. The experience of (2.) leads to the question: Do I need to tune the priorities of each thread based on a kind of state machine? In my understanding that's not needed as the RTOS should take care of the scheduling itself?!

4. (off-topic) I read that a thread may terminate or suspend itself, not another one. Can it be resumed/reset by any other thread or are there conditions, that thread A has to fulfill to be able to resume/reset thread B (of course thread B has to be suspended/terminated before)?

 

Thanks in advance!

 

0 REPLIES 0