# AudioThreadGuard - keep your audio thread clean

**URL:** <https://forum.juce.com/t/audiothreadguard-keep-your-audio-thread-clean/28532>\
**Category:** Useful Tools and Components\
**Created:** [July 13, 2018, 11:49am UTC](https://forum.juce.com/t/audiothreadguard-keep-your-audio-thread-clean/28532 "2018-07-13T11:49:30Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![matkatmusic](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@matkatmusic](https://forum.juce.com/u/matkatmusic)\
**Post date:** [July 20, 2018, 8:46am UTC](https://forum.juce.com/t/audiothreadguard-keep-your-audio-thread-clean/28532/15 "2018-07-20T08:46:52Z")

</div>

some of 'em aren’t lock free! I showed the source for std::atomic\<shared\_ptr\> here, which is not lock free. just a head’s up.

> [@Timur Doumler Talks on C++ Audio (Sharing data across threads)](https://forum.juce.com/t/timur-doumler-talks-on-c-audio-sharing-data-across-threads/26311):
>
> So, i’ve been watching his talks about how to do safe object exchange without blocking and being lock-free. His end solution is something like this: class Synth { public: //this is the user of the widget void audioCallback(float\* buffer, int bufferSize) { std::shared\_ptr\<T\> widgetToUse = std::atomic\_load(&currentWidget); //use widget with your buffer } //this is the creator of the widget void updateWidget(/\*args \*/) { std::shared\_ptr\<T\> …

---

_[View the full topic](https://forum.juce.com/t/audiothreadguard-keep-your-audio-thread-clean/28532)._
