6 years, 10 months ago.

question about the RTOS member function get_state()

It can only be called from a running task, so it will always return "Running". Seems like a useless function. What am I missing?

1 Answer

6 years, 10 months ago.

I don't know that I really have an answer, but get_state() is a public member function so get_state() can be called by the module that created/owns the Thread. So if you create a Thread my_thread, in main(), you can call my_thread.get_state() from main(). Obviously if you call it from main(), my_thread will never be in the running state at the point when you get the state. How would you put this function to practical use? I'm not sure I can say.

When RTOS is included, "main" is an RTOS thread, so a call to get_state would presumably return the state of the running "main" thread.

posted by Alfred Hume 04 Jan 2018