What is task state in real time operating system

Hi team

I do not understand when I think of task state (ready, running, blocked) in the terms of in real time operating system. There may be multiple task's but processor only execute one task at one time.

Let's say we have three tasks

  • turn on and off led
  • read the switch button
  • run motor

When led is on and motor is running is it called led and motor is ready to run ?

(deleted)

In an RTOS, the task state consists of a snapshot of all the processor registers, along with an individual heap and stack memory allocation for each task (process). A system timer ensures that each task can not run for longer than some maximum time interval. A process may relinquish control voluntarily if it has nothing to do. Task switching is performed by swapping processor registers and memory allocations. The RTOS manages multitasking mostly transparently, so that each task seems to be independent.

Your question does hinge on terminology a little. The meaning of your 3 terms might vary from place to place. In an RTOS, a "running" task is the one that is currently loaded in the processor registers. I think a "ready" task is one that is waiting its turn to be loaded. A "blocked" task is one that, when loaded, discovers that it can't continue processing, so relinquishes control to the next task via the scheduler. Note that in a sophisticated RTOS, there may be a HAL layer that interfaces with the RTOS directly. So a process might be blocked for I/O and the HAL would test whether it can continue or not, instead of the process code. Thus in a simple RTOS with no HAL, no processes can be excluded from the active list by the scheduler, since the blocking state is known only to the process, not the RTOS. In that case, the difference between "ready" and "blocked" is dependent on the conditions that the process encounters when it is "running".

In other words, with an RTOS (the embedded kind especially), the "running" state is determined by the OS, and the "ready" or "blocked" state is managed by the application code. "blocked" code is just code that will test and find nothing to do, and call a relinquish() function to pass control. "ready" is the same code when it tests and finds that there is work to do, then it will continue to run until it either blocks, or times out.

With cooperative multitasking, the task state is maintained in conventional variables, or if the need arises for a large number of states, state variables. Tasks are designed by the programmer, to always relinquish control before a maximum time interval has elapsed. The main task (i.e. the program) always has the same registers and memory allocation. There is usually no core support for it, the logic is embedded in the program.

Have a read of process state.
Like spycatcher2k I can't really see how this is relevant to Arduino.

But in an attempt to answer to your question...

When led is on and motor is running

Tasks 1 and 3 should be "Blocked".

If they were "Ready" it would mean that they are currently performing some processing, but are not currently running due to the CPU being used by another task.

But since it doesn't require CPU cycles to light a led or run a motor (only to make them change state), and by implication those tasks only have those specific tasks to do, then these should be "Blocked" waiting for some external input to tell them to change state.

Rehan11:
I do not understand when I think of task state (ready, running, blocked) in the terms of in real time operating system.

This question is too vague. If there is an Operating System then what is it?

If the question relates to some Arduino program you are creating then please post the program.

...R

pcbbc:
Have a read of process state.
Like spycatcher2k I can’t really see how this is relevant to Arduino.

But in an attempt to answer to your question…Tasks 1 and 3 should be “Blocked”.

If they were “Ready” it would mean that they are currently performing some processing, but are not currently running due to the CPU being used by another task.

But since it doesn’t require CPU cycles to light a led or run a motor (only to make them change state), and by implication those tasks only have those specific tasks to do, then these should be “Blocked” waiting for some external input to tell them to change state.

Thanks for that clarification. There are RTOS for Arduino, and it may be useful to people who have boards with more memory than legacy Arduino designs.

Upon some thought, the stated tasks would not usually be implemented as separate processes in an RTOS, because they would usually interact actively (e.g. switch controls motor and LED indicates status or whatever) as a single application. Interprocess communication is not as simple as sharing some variables. I think that is why the answer that they are all blocking (note that I include the switch because most of the time it does not change state) seems counter intuitive. It’s a really artificial scenario.

Thanks for explanation. micro-controllers run at very high speed as compared to mechanical components Consider Task A control component 1, Task B control component 2 and Task C is to control component 3. component has its on state running and off

my question is same I do not understand when I think of task state (ready, running, blocked) in the terms of in real time operating system for all three components.

Rehan11:
Thanks for explanation. micro-controllers run at very high speed as compared to mechanical components Consider Task A control component 1, Task B control component 2 and Task C is to control component 3. component has its on state running and off

my question is same I do not understand when I think of task state (ready, running, blocked) in the terms of in real time operating system for all three components.

Your question is too abstract and vague to answer specifically. You have to specify an actual software environment, because there are many different kinds. Tasks are handled differently in different systems, as explained by several people above.

I’m essentially directing you back to reply #4.

Rehan11:
Thanks for explanation. micro-controllers run at very high speed as compared to mechanical components Consider Task A control component 1, Task B control component 2 and Task C is to control component 3. component has its on state running and off

my question is same I do not understand when I think of task state (ready, running, blocked) in the terms of in real time operating system for all three components.

You seem to be confusing the software task state, with the physical state of the component. They may use the same language (e.g. "running") but they are not the same concepts.

Just because a motor is "running" a task that may be controlling it does not need to be. A motor generally runs until some task commands it otherwise, for example by changing a pin state or adjusting a PWM output. But just to keep the motor in its current state does not require any running tasks.

aarg:
You have to specify an actual software environment, because there are many different kinds

arduino IDE but it would to early to come on programming side because I do not have much understanding on basics. That’s what doing to understand basics

pcbbc:
You seem to be confusing the software task state, with the physical state of the component.

Task may be anything like turn on and off led, read the switch button, run motor

We have 3-Tasks with different priorities. 3-Tasks(Task1, Task2 and Task) are with priorities 3, 2, 1
I am very confuse with terms task is ready to run on processor. Can you clarify what it mean in the context of three task. you can either take one of your example for tasks

Rehan11:
to early to come on programming side because I do not have much understanding on basics.

Then perhaps jumping into the middle of an advanced topic like this isn't the best approach to learning the basics.

Rehan11:
We have 3-Tasks with different priorities. 3-Tasks(Task1, Task2 and Task) are with priorities 3, 2, 1
I am very confuse with terms task is ready to run on processor. Can you clarify what it mean in the context of three task. you can either take one of your example for tasks

You are not nearly as confused as we are.

Please go back to basics and describe the project you want to create. I suspect the solution will be a great deal easier than you imagine.

…R

gfvalvo:
Then perhaps jumping into the middle of an advanced topic like this isn't the best approach to learning the basics.

I have been looked through Wikipeadia as well as I have visited other websites. I have seen diagram of task state. I understand the each state of task in diagram

Running (Task is executing on the processor)
Ready (Task is ready to be executed)
Blocked (Task is waiting for an event)

But when I think practically if I have some electronic devices (sensor, switch , relay anything )connected to the Arduino board. Then I do not understand what the task state is for them in the context of real time operating system. I hope you understand what I am asking

Rehan11:
Arduino board. Then I do not understand what the task state is for them in the context of real time operating system. I hope you understand what I am asking

'Nothing' as the devices connected to the uController/RTOS do not know about the RTOS.

freeRTOS docs FreeRTOS - Task Control Functions and Macros for the Free Open Source RTOS FreeRTOS

Rehan11:
I hope you understand what I am asking

We did, and we answered. On the other hand, we asked you what you are planning to build (reply #11) and we're still waiting for an answer.

You're asking a nonsensical question unless you're planning to actually use an RTOS on an Arduino.

The basic Arduino is a single core slow CPU with a single thread and no hardware support that I know of to help multi tasking.

If you need to read a switch, flash a led and run a motor though, it's plenty fast enough to keep up with your puny human reaction time without you realizing that it's not running multiple threads.

In consequence, thinking about how to run your Arduino code in terms of processes, task switching or threads is not helpful because they're not there. All that is needed is millis to fake the user out into thinking that things are being handled simultaneously. If you actually need that power, consider a Pi.

aarg:
We did, and we answered. On the other hand, we asked you what you are planning to build (reply #11) and we're still waiting for an answer.

Really i am not going to make anything but the project requirement is so important to understand basic then i give an example

Candy Sorting Machine conveyor : candy are coming one by one on the conveyor and we need to sort good and bad candy good candy will goes to collection bin while bad candy will goes to rejection bin.

I think this is a real time system because candy comes in queue, at very high speed. system has to be decide, is it good or bad in limited time

following are main parts of sorting machine

Microcontroller : It will control the I/O devices
Camera : Camera will take image of device and decide it's good or bad part of image processing
sensor : sensor will detect candy if there is candy then activate candy other wise camera will not operate
pusher : Pusher will push candy to bin
panic button switch : when something bad happen sorting machine should be shutdown automatically

Of course, we can do this by writing sequential program but if we want to do it by rtos. Now my question is the same as before. What would be task state for Candy Sorting Machine?

Of course, we can do this by writing sequential program but if we want to do it by rtos. Now my question is the same as before. What would be task state for Candy Sorting Machine?

“Candy Sorting Machine” is not a task.

I have a (likely wrong) feeling that the op's asking for a state diagram.

Rehan11:
Of course, we can do this by writing sequential program but if we want to do it by rtos. Now my question is the same as before. What would be task state for Candy Sorting Machine?

That's a bit like saying "I know how to make it with wood, but how can I make it with something else". It's impossible to answer such a vague question without writing a text book. I'm sure there are plenty of existing text books about Operating Systems, in bookshops and online.

If you were doing the project on an Arduino the answer would be simple - you don't need an RTOS, it won't add any value to the finished product and it will just waste precious CPU cycles.

...R