Algorithm

bewafa

Member
How will MD act when some actions were already running and then other actions of the same macro get triggered. Then, actions of both invocations will act simultaneously?
 

FrameXX

Well-known member
Then, actions of both invocations will act simultaneously?

Yes. MacroDroid will just run the thread again no matter if it's already running or not, so there can be 2 executions of a list of actions, each execution running a different action. For example, one execution may execute a few actions behind the other execution because it was triggered later.

This could potentially break your macro if you are not prepared for it, especially in cases where the later execution of the actions changes the values of variables that the other execution still works with and relies on their values! In these cases you can use the "Macro Not Invoked" constraint or other tricks... If your macro is going to be triggered a lot, usually before the previous execution has finished, it may be a good idea to use an action block. An action block sends the execution with its own input data into an isolated environment where it runs with its own local variables and can't interfere with other simultaneous executions of the macro.
 
Last edited:

Endercraft

Moderator (& bug finder :D)
I believe this is not exactly true. MacroDroid will indeed run a macro again even if it is already running, but not simultaneously. That goes for every macro too. The first thread will run, then the next will. The only way to make this next one run before the first thread is finished is to have any wait of any kind in your macro that the first thread will reach. In this case, the next thread will be able to run.
 

FrameXX

Well-known member
I believe this is not exactly true. MacroDroid will indeed run a macro again even if it is already running, but not simultaneously.

Try to test trigger of this macro multiple times. The numbers will add up faster and faster. Of course the will reset to zero on every trigger test.
 

Attachments

  • Test.macro
    3.6 KB · Views: 3

Endercraft

Moderator (& bug finder :D)
MacroDroid will indeed run a macro again even if it is already running
I'm pretty sure there was a bug with that too where the first thread would be deleted by MacroDroid.
Try to test trigger of this macro multiple times. The numbers will add up faster and faster. Of course the will reset to zero on every trigger test.
That confirms my experience with wait actions.
The only way to make this next one run before the first thread is finished is to have any wait of any kind in your macro that the first thread will reach. In this case, the next thread will be able to run.
I'll try and verify if it indeed works without wait. I'm not sure how to do it without lagging my device or any side effects. Problem is MacroDroid will kill that thread for running too fast (at 200 actions ran fast I think).
 

FrameXX

Well-known member
The problem I am describing will not normally affect lists of actions that use asynchronous actions such as Set Variable, Sent Intent, Configure Wi-Fi etc... which take almost no time to execute, but may cause problems in lists of actions that use synchronous actions such as HTTP GET or Shell Script (with "Wait until action ends" checked).
 

Endercraft

Moderator (& bug finder :D)
I was able to confirm macros run in order.
Screenshot_2023-03-19-10-22-15-554-edit_com.arlosoft.macrodroid.jpg
After triggering, the macro ended up at 6. If it was simultaneously running, it would have ended up around 11.

Nevermind, the macro only triggered once.
The problem I am describing will not normally affect lists of actions that use asynchronous actions such as Set Variable, Sent Intent, Configure Wi-Fi etc... which take almost no time to execute, but may cause problems in lists of actions that use synchronous actions such as HTTP GET or Shell Script (with "Wait until action ends" checked).
I understand what you meant now. Yes, that will indeed cause problems, especially if the next thread skips a wait action. Of course there are way to prevent this.
 

Dm114

Well-known member
I believe this is not exactly true. MacroDroid will indeed run a macro again even if it is already running, but not simultaneously. That goes for every macro too. The first thread will run, then the next will. The only way to make this next one run before the first thread is finished is to have any wait of any kind in your macro that the first thread will reach. In this case, the next thread will be able to run.
Sorry but you are wrong: what @FrameXX describes is the way MD works. There were threads about the way macros can run concurrently, many years ago on the old forum version.
 
Top