# Are variables thread-safe?

**URL:** <https://community.homey.app/t/are-variables-thread-safe/25401>\
**Category:** Flows\
**Created:** [February 3, 2020, 8:56am UTC](https://community.homey.app/t/are-variables-thread-safe/25401 "2020-02-03T08:56:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![azurIt](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/azurit/32/16498_2.png) [@azurIt](https://community.homey.app/u/azurIt)\
**Post date:** [February 3, 2020, 8:56am UTC](https://community.homey.app/t/are-variables-thread-safe/25401/1 "2020-02-03T08:56:43Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![KonradWalsh](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/konradwalsh/32/147_2.png) [@KonradWalsh](https://community.homey.app/u/KonradWalsh)\
**Post date:** [February 3, 2020, 9:09am UTC](https://community.homey.app/t/are-variables-thread-safe/25401/2 "2020-02-03T09:09:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![azurIt](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/azurit/32/16498_2.png) [@azurIt](https://community.homey.app/u/azurIt)\
**Post date:** [February 3, 2020, 9:11am UTC](https://community.homey.app/t/are-variables-thread-safe/25401/3 "2020-02-03T09:11:10Z")

</div>

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’.

---

<div class="post-metadata">

**Author:** ![KonradWalsh](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/konradwalsh/32/147_2.png) [@KonradWalsh](https://community.homey.app/u/KonradWalsh)\
**Post date:** [February 3, 2020, 9:16am UTC](https://community.homey.app/t/are-variables-thread-safe/25401/4 "2020-02-03T09:16:32Z")

</div>

they are not local variables… they are not thread safe

---

<div class="post-metadata">

**Author:** ![azurIt](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/azurit/32/16498_2.png) [@azurIt](https://community.homey.app/u/azurIt)\
**Post date:** [February 3, 2020, 9:17am UTC](https://community.homey.app/t/are-variables-thread-safe/25401/5 "2020-02-03T09:17:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [February 3, 2020, 9:18am UTC](https://community.homey.app/t/are-variables-thread-safe/25401/6 "2020-02-03T09:18:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![azurIt](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/azurit/32/16498_2.png) [@azurIt](https://community.homey.app/u/azurIt)\
**Post date:** [February 3, 2020, 9:23am UTC](https://community.homey.app/t/are-variables-thread-safe/25401/7 "2020-02-03T09:23:37Z")

</div>

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.
