Are variables thread-safe?

Hi,

are variables, which can be set in ‘Logic’ section, thread-safe? I mean, if will multiple flows work with the same variable, will it stay consistant?

They are global variables. You can set them from any flow or script. However, they will remain consistent across flows as they will show the value that was last set.

1 Like

You misunderstood me.

I have a numerical variable which i’m using as a counter, so multiple flows are increasing/decreasing it. If variables are not thread-safe, this will not work and in some time, variable will became inconsistant as some changes will be ‘missing’.

they are not local variables… they are not thread safe

‘not local variables’ doesn’t mean ‘not thread-safe’, are you a programmer?

We can’t be 100% certain because this is a part of Homey’s core that no regular user can access, but an educated guess would be that variables are managed from a single piece of code that is thread-safe (or rather, will not run multithreaded).

However, I don’t think there will be a transaction-like mechanism, where if you use a variable in a condition you are guaranteed that it will have the same value when you use it in an action in the same flow.

2 Likes

Thanks for opinion.

In this specific case, i’m using that variable only in ‘then’ card but thank you for pointing this out as i will use it also in conditions in the future and it didn’t comes to my mind.