Situation to run tow tasks simultaneously

What is the situation in which two tasks have to run simultaneously.

Let’s say we have two physical ( start and stop) buttons and two buttons ( start and stop) have been created in the web application, so the job of all of them is to control a light.

I see two Tasks in this situation, which should be run simultaneously.

Task 1: Monitor physical buttons to control lighting

Task 2 : Monitor buttons on web application to control lighting

I see the situation here when both the tasks should run simultaneously.

What do you think about it?

If that is all the system was doing I would have the processor in sleep mode most of the time - with the buttons wired up to interrupts that bring the system out of sleep to do whatever is necessary when the button went back to sleep. No operating system needed.

Not sure of the relevance of the web application.

1 Like

First, it depends a LOT on your definition of “Running”. As Richard Barry says, those tasks are running in the sense that they have been created, but they are blocked waiting for requests.

Push Buttons should, as he said, generate an interrupt and the ISR post an message to the button task.

For the web application, the system will need a server application to accept the https requests, waking up with each packet from the Internet, and that task can send a message to the button task, perhaps even the exact same message as the button ISR does. After all, does the controller care which button was pushed (real or on-line), it just wants to respond to them.

When nothing is happening, both those tasks are just blocked waiting for something.

Note, unless you have a multi-core processor, two tasks can’t ACTUALLY be running at the same time, one might be running and the other ready, and if they take long enough to do their job, they might gets switched back and forth between each other, looking like both are running.

1 Like