Fundamental of task state and state transaction

Thread Starter

Sparsh45

Joined Dec 6, 2021
143
I am trying to understand the fundamental of Task State and State Transition in the context of real time operating systems. I found a very good explanation of the Task state on the wikipedia page. https://en.m.wikipedia.org/wiki/Process_state

Single core CPU can only run one task at a time. Each of the tasks can be in any states at any instant of time.

in typical designs, a task has three states

  1. Running (task executing on the CPU)
  2. Ready (task ready to be executed)
  3. Blocked (task waiting for an event)

I understand what is "running" and "ready to run state".

I don't fully understand what the blocking, waiting, terminated and suspended state are ?
 

Thread Starter

Sparsh45

Joined Dec 6, 2021
143
( e.g. the motors must be shut off within 1/10 second after hitting the limit switch to avoid permanent damage. )

Is this an example of a blocking state as the switch is waiting for the button to be hit.
 

djsfantasi

Joined Apr 11, 2010
9,156
A blocking state is when an external MP3 player has been instructed to play a file and nothing else IN THAT TASK can be done until the file has completed being played.

Or any external device is doing something and the task cannot be continued before the external device completes its own task.
 

Thread Starter

Sparsh45

Joined Dec 6, 2021
143
You list three states and then identify six states?
Wikipedia page shows only three states. The word "terminate" confuses me I don't understand what it is but it is used in operating systems. This word is also used in the link

Similar "waiting" and "suspend" words have been used at some places which is very confusing.

( e.g. the motors must be shut off within 1/10 second after hitting the limit switch to avoid permanent damage. )

Is this an example of a blocking state as the switch is waiting for the button to be hit.
@djsfantasi
Which state does my example justify?
 
Last edited:

Thread Starter

Sparsh45

Joined Dec 6, 2021
143
I have looked at least 15 to 20 websites for specific example but I can't find explanation anywhere with specific example. Does anyone know a specific example.
 

djsfantasi

Joined Apr 11, 2010
9,156
Which state does my example justify?
I gave my one example, because your example does not provide enough information. It could be blocking, if your test for the limit switch is inline with the task code. If the limit switch test is interrupt based, then it’d not an example of blocking.
 

Thread Starter

Sparsh45

Joined Dec 6, 2021
143
I gave my one example, because your example does not provide enough information. It could be blocking, if your test for the limit switch is inline with the task code.
Do you get any idea now? There are five task's ready to run. Can we get many states and state transition with example

C:
// Task 1
void Motor_Task ()
{
    Motor = OFF;
   
    while (1)
    {
        if ( SWITCH == PRESSED )
        {
            Motor = Run_Motor;
        }
    }
}

// Task 2 run every 1ms time
void Counter_Task ()
{
    unit8_t counter = 0 ;
   
    while (1)
    {
        if ( Sensor == Activated )
        {
            counter++;
        }
    }
   
}

// Task 3
void Emergency_Stop()
{
    while (1)
    {
        if ( Emergency_SWITCH == PRESSED )
        {
            Motor = Motor_Stop;
        }
    }
}
// Task 4
void Display ()
{
    while (1)
    {
      LCD_SEND(Counter);
    }
   
}

// Task 5
void PC_Data()
{

     while (1)
    {
      UART_SEND(Counter);
    }  
}


void main ()
{
    INIT_SYSTEM();
   
    while (1)
    {
       
    }
}
 
Last edited:

djsfantasi

Joined Apr 11, 2010
9,156
Do you get any idea now? There are five task's ready to run. Can we get many states and state transition with example

C:
// Task 1
void Motor_Task ()
{
    Motor = OFF;
  
    while (1)
    {
        if ( SWITCH == PRESSED )
        {
            Motor = Run_Motor;
        }
    }
}

// Task 2 run every 1ms time
void Counter_Task ()
{
    unit8_t counter = 0 ;
  
    while (1)
    {
        if ( Sensor == Activated )
        {
            counter++;
        }
    }
  
}

// Task 3
void Emergency_Stop()
{
    while (1)
    {
        if ( Emergency_SWITCH == PRESSED )
        {
            Motor = Motor_Stop;
        }
    }
}
// Task 4
void Display ()
{
    while (1)
    {
      LCD_SEND(Counter);
    }
  
}

// Task 5
void PC_Data()
{

     while (1)
    {
      UART_SEND(Counter);
    } 
}


void main ()
{
    INIT_SYSTEM();
  
    while (1)
    {
      
    }
}
No, I have nothing more to add. As I’ve said in another thread, you seem to be unteachable, because you don’t seem able to understand basic concepts, where they are appropriate and how to apply them.

What results is a mish-mash of unrelated ideas and people who try to help you get frustrated. I tried again, but I’m sorry to say I’m done. With all of your posts. This site has an ignore list and you have earned a place on mine.

Best of luck!
 

Thread Starter

Sparsh45

Joined Dec 6, 2021
143
What results is a mish-mash of unrelated ideas and people who try to help you get frustrated. I tried again, but I’m sorry to say I’m done. With all of your posts. This site has an ignore list and you have earned a place on mine.

Best of luck!
I chose a topic and tried to understand it. I attached the link of the topic where I am getting stuck. I explained what I understand and what I don't understand. I explained the problem in detail and asked a specific question, I gave a possible solution to my problem which I thought might be.

I don't understand how one would understand task state and task transition with specific examples as many tutorials only show concepts but actual examples are not given. How would one create a specific example for each states.

I'm disappointed because I haven't been able to find a specific example for each state yet, and haven't been able to find an example for how the state will move from state to state.
 
Last edited:

boostbuck

Joined Oct 5, 2017
501
You are having difficulty understanding blocking and need an example to clarify the definition. However, the page you link to has a clear definition, including a simple example to illustrate.

What is it about the example supplied (blocking on print operation when printer is unavailable) that you a having difficulty understanding?

Or 'terminated', for example. Can you clarify what is confusing about the explanation on the linked wikipedia page?
 

Thread Starter

Sparsh45

Joined Dec 6, 2021
143
Can you clarify what is confusing about the explanation on the linked wikipedia page?
I understand defination, need an example to clarify the definition

Blocked
A task is said to be in the Blocked state if it is currently waiting for external event.

However, the page you link to has a clear definition, including a simple example to illustrate.
definition is there but i don't see any example.

What is it about the example supplied (blocking on print operation when printer is unavailable) that you a having difficulty understanding?.
Cannot print until printer is available
 

boostbuck

Joined Oct 5, 2017
501
What is it about the example supplied (blocking on print operation when printer is unavailable) that you a having difficulty understanding?
 

BobTPH

Joined Jun 5, 2013
8,813
I really hate to say this. I am not trying to be mean, and it is not said to appease my frustration. Not everyone is a “rocket scientist”, and some concepts cannot really be understood by those who are not. Perhaps multitasking is beyond your capability of understanding.

Bob
 

Thread Starter

Sparsh45

Joined Dec 6, 2021
143
I really hate to say this. I am not trying to be mean, and it is not said to appease my frustration. Not everyone is a “rocket scientist”, and some concepts cannot really be understood by those who are not. Perhaps multitasking is beyond your capability of understanding.

Bob
The problem with me is that I want to apply the theoretical concepts to a practical situation where I am having problems. I think I've tried my best to understand.

Now I am looking for help from anyone who understands this concept with practical example. I hope someone will present his idea with real example, please just avoid defination and explain idea with specific examples
 

boostbuck

Joined Oct 5, 2017
501
I understand defination, need an example to clarify the definition
The definition of 'terminated' in your linked page to my mind is very clear and gives very specific practical examples of what this state involves. You haven't explained what it is you don't fully understand about these states, or the examples used.

If by 'an example to clarify' you mean you are looking for a turn-key solution of code examples to directly implement (even though perhaps your level of understanding precludes creating these yourself) you are probably going to have to do a lot more googling on your own account.

Your original question implies you want to understand the concepts. Consequently you are being given an overview with general illustrations, rather than specific solutions.
 

Thread Starter

Sparsh45

Joined Dec 6, 2021
143
If by 'an example to clarify' you mean you are looking for a turn-key solution of code example
No i didn't ask for any code example

Your original question implies you want to understand the concepts. Consequently you are being given an overview with general illustrations, rather than specific solutions.
I understand the concept but I don't understand how to apply for any specific project.

Ready
Ready tasks are those that are able to execute but are not currently executing on the CPU.

Running
When a task is actually executing it is said to be in the Running state. It is currently utilising the processor.

Blocked
A task is said to be in the Blocked state if it is currently waiting for external event.

Specific project means such as aircraft control systems, robot, MRI scan, satellite missile system. I think these are all projects where operating system is required.

The task of a typical project is divided into several tasks for the operating system. Each task is executed on the system in such a way that it is executed at the time when it is needed.

I was looking for a small and simple specific project in which I want to understand the states of the task ( ready, running, blocked ) by dividing the task into sub tasks
 

boostbuck

Joined Oct 5, 2017
501
Well, if you don't feel like creating your own preemptive task switcher, how about this taking as an example: FreeRTOS
It seems to have everything you ask, and the demo projects are small and simple. Getting an understanding of that should clarify how the concepts are applied to a project.
 

Thread Starter

Sparsh45

Joined Dec 6, 2021
143
how about this taking as an example: FreeRTOS
It seems to have everything you ask, and the demo projects are small and simple. Getting an understanding of that should clarify how the concepts are applied to a project.
Suppose Task 1 takes 20% CPU time so we have 80% free CPU time for other tasks.

In which state, task 1 will a go after using 20% of the CPU time? ( Blocked or waiting or suspended ) ?
 

boostbuck

Joined Oct 5, 2017
501
Okay, I think you need to recognise you do NOT understand the fundamental behaviour of preemptive switching of process by an operating system.

The piece you appear to be missing is the idea that the supervisory program switches each of several processes in and out of RUNNING state.

I suggest you think very carefully about the behaviour of the operating system as it switches context between each process, and each process is executed until it runs out of allowed cpu time (and the OS then switches the next process in) OR the process blocks on an external resource requirement (and it signals the OS that it surrenders it's timeslice) OR finishes OR is terminated (and the OS removes it from the process collection).

To answer your question, a process is taking 20% of the CPU for a reason. For example:

A process will take 20% CPU time in a queue of five CPU bound processes, as the scheduler will only allocate 20% of the CPU time to each process. 20% is it's fair share in the switching algorithm, in which case it goes from RUNNING to READY, waiting to be allocated more time.

OR

In a queue of several other processes, it will only take 20% of the CPU time if it blocks on resource frequently and the others will be allocated more CPU time (while the first waits for the block to clear). So the process frequently waits for an external resource, and surrenders it's timeslice, going from RUNNING to BLOCKED, waiting to be allocated more CPU time to check if the block is cleared.
 
Top