# Callback Thread vs Main Thread - Is Locking Required?

**URL:** <https://qa.fmod.com/t/callback-thread-vs-main-thread-is-locking-required/18159>\
**Category:** Unity\
**Created:** [December 31, 2021, 3:57am UTC](https://qa.fmod.com/t/callback-thread-vs-main-thread-is-locking-required/18159 "2021-12-31T03:57:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![VoodooDetective](https://avatars.discourse-cdn.com/v4/letter/v/ecc23a/32.png) [@VoodooDetective](https://qa.fmod.com/u/VoodooDetective)\
**Post date:** [December 31, 2021, 3:57am UTC](https://qa.fmod.com/t/callback-thread-vs-main-thread-is-locking-required/18159/1 "2021-12-31T03:57:17Z")

</div>

I know I shouldn’t be running Unity code in an FMOD callback (that seems to crash Unity to desktop), so my question is: if I want to share data from and FMOD callback with the main Unity thread, do I need to be using locks? Do those two threads run concurrently?

I guess I’m asking if I should use a Queue or a ConcurrentQueue from messages from the FMOD callback to Unity’s main thread.

---

<div class="post-metadata">

**Author:** ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)\
**Post date:** [December 31, 2021, 5:49am UTC](https://qa.fmod.com/t/callback-thread-vs-main-thread-is-locking-required/18159/2 "2021-12-31T05:49:47Z")

</div>

Thread safety is a concern with callbacks as they can be called from multiple different FMOD threads, and Unity throws an exception whenever the API is called on anything other than the main thread as you’ve seen.  
We have a [Thread Safety doc](https://fmod.com/resources/documentation-api?version=2.02&page=white-papers-threads.html) with some general advice on how to use the FMOD API in a thread-safe (or unsafe) way. For the scenario you are desribing, I think a ConcurrentQueue/ConcurrentStack would be a good way to go as it is lock free, which is preferable in real time audio applications.
