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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Sarra.S
ST Employee

Hello @MGuth.1

I highly suggest going through the couple of videos provided by ST in this MOOC: STM32Cube and Azure RTOS hands-on workshop - STMicroelectronics 

1/2. In your case, it seems that the default configuration does not enable time slicing, since both user threads have the same priority and no time slicing is enabled, the first thread that starts running will continue to run indefinitely unless it yields, waits for something, or is preempted by a higher-priority thread. 

3/ No, the RTOS should take care of the scheduling itself

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

2 REPLIES 2
Sarra.S
ST Employee

Hello @MGuth.1

I highly suggest going through the couple of videos provided by ST in this MOOC: STM32Cube and Azure RTOS hands-on workshop - STMicroelectronics 

1/2. In your case, it seems that the default configuration does not enable time slicing, since both user threads have the same priority and no time slicing is enabled, the first thread that starts running will continue to run indefinitely unless it yields, waits for something, or is preempted by a higher-priority thread. 

3/ No, the RTOS should take care of the scheduling itself

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi Sarra


Thank you very much for your answer! You are totally on point, I overlooked the default configuration that does not allow for time slicing. Now everything makes sense in my tiny little world again :)

 

Now heading on by using ThreadX for something useful! ;)