# Is it safe to use std::mutex::try\_lock or ScopedTryLock on the realtime thread?

**URL:** <https://forum.juce.com/t/is-it-safe-to-use-std-try-lock-or-scopedtrylock-on-the-realtime-thread/28198>\
**Category:** General JUCE discussion\
**Created:** [June 20, 2018, 8:46am UTC](https://forum.juce.com/t/is-it-safe-to-use-std-try-lock-or-scopedtrylock-on-the-realtime-thread/28198 "2018-06-20T08:46:40Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![nicolasdanet](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/nicolasdanet/32/56_2.png) [@nicolasdanet](https://forum.juce.com/u/nicolasdanet)\
**Post date:** [March 1, 2021, 4:59pm UTC](https://forum.juce.com/t/is-it-safe-to-use-std-try-lock-or-scopedtrylock-on-the-realtime-thread/28198/3 "2021-03-01T16:59:59Z")

</div>

FYI : few more thoughts in another Timur Doumler’s talk (at 10 minutes / [https://www.youtube.com/watch?v=zrWYJ6FdOFQ](https://www.youtube.com/watch?v=zrWYJ6FdOFQ)).

Future reader should read that also: 😀

> [@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/is-it-safe-to-use-std-try-lock-or-scopedtrylock-on-the-realtime-thread/28198)._
