# Safety of ValueTree inside processBlock()

**URL:** <https://forum.juce.com/t/safety-of-valuetree-inside-processblock/7031>\
**Category:** General JUCE discussion\
**Created:** [June 16, 2011, 8:25am UTC](https://forum.juce.com/t/safety-of-valuetree-inside-processblock/7031 "2011-06-16T08:25:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![masshacker](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/masshacker/32/650_2.png) [@masshacker](https://forum.juce.com/u/masshacker)\
**Post date:** [June 16, 2011, 8:25am UTC](https://forum.juce.com/t/safety-of-valuetree-inside-processblock/7031/1 "2011-06-16T08:25:52Z")

</div>

Is it safe to retrieve properties from a ValueTree inside AudioProcessor’s processBlock function and use them during the process?  
Should I use a lock?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [June 16, 2011, 8:51am UTC](https://forum.juce.com/t/safety-of-valuetree-inside-processblock/7031/2 "2011-06-16T08:51:00Z")

</div>

ValueTree is definitely not thread-safe, you’d need to use locking.

---

<div class="post-metadata">

**Author:** ![masshacker](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/masshacker/32/650_2.png) [@masshacker](https://forum.juce.com/u/masshacker)\
**Post date:** [June 16, 2011, 9:24am UTC](https://forum.juce.com/t/safety-of-valuetree-inside-processblock/7031/3 "2011-06-16T09:24:26Z")

</div>

Good to know, thank you.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [June 16, 2011, 11:04am UTC](https://forum.juce.com/t/safety-of-valuetree-inside-processblock/7031/4 "2011-06-16T11:04:55Z")

</div>

…and I should also say that I strongly recommend NOT using it in realtime code. Its operations can block unpredictably.

---

<div class="post-metadata">

**Author:** ![masshacker](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/masshacker/32/650_2.png) [@masshacker](https://forum.juce.com/u/masshacker)\
**Post date:** [June 16, 2011, 11:16am UTC](https://forum.juce.com/t/safety-of-valuetree-inside-processblock/7031/5 "2011-06-16T11:16:51Z")

</div>

So what would be the best way? All the informations I need are stored into ValueTrees…  
Should I use variables to store the infos, updating them with ValueTree::Listener?

---

<div class="post-metadata">

**Author:** ![dave96](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dave96/32/8487_2.png) [@dave96](https://forum.juce.com/u/dave96)\
**Post date:** [June 16, 2011, 12:59pm UTC](https://forum.juce.com/t/safety-of-valuetree-inside-processblock/7031/6 "2011-06-16T12:59:28Z")

</div>

I did a similar thing before (had multiple issues when using a ValueTree in the audio thread) so I used a local set of atomics which I set in the value tree callback and used these in the audio callbacks. May not be the most efficient way of storing variable but it worked.

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [June 18, 2011, 5:20pm UTC](https://forum.juce.com/t/safety-of-valuetree-inside-processblock/7031/7 "2011-06-18T17:20:12Z")

</div>

Give each thread it’s own copy of the data and use a thread queue to propagate changes.
