Go Down

Topic: Pseudo parallel processing or a kind of multi-threading (Read 162 times) previous topic - next topic


Hi guys,

Many of us have needed to use the controller to do something while waiting on an other process...

There are many ways to do that and one of the most efficient is shown by Robin2 on the following example:

I took the time to implement it in a library:

It's very efficient because it uses no resources such as timers and you can set up many asynchronous processes.

To call a cyclic routine we just need to declare an instance of the class PseudoParallelProcessing referring to the subroutine it will cyclically call:

       PseudoParallelProcessing multiTasker1(CyclicProcess);

Create the Subroutine with the cyclic process you want to execute:

       void CyclicProcess()
          Serial.println("Counter = " + String(iCounter)); 

And finally run it every cycle, it will determine if it is time to run the routine and if not it will just free the processor for the next task (The first parameter is the interval between execution scan and the second is the current time (both in ms):

       multiTasker1.RunIt(500, iNow);

Check the Example to see how to manage multiple tasks each with it's own execution rate, it's very intuitive to use.


From a quick look it seems to work the same as Several Things at a Time

Why are you restricting it to use integer versions of the value of millis()?

Two or three hours spent thinking and reading documentation solves most programming problems.


Yes it does! With a little less coding for the user.

Since I never needed intervals longer then a few seconds, I guessed I should save a couple of bytes by restricting the millis() output to int. (In many of my pojects I end up having to reduce memory usage).

But it can be changed!

Go Up