#summary Threading, locking, synchronization, and related issues.
= Introduction =
We have a variety of mechanism to help us when working in multithreaded contexts. * full-on locking using the TTMutex class * lightweight spin-locking where we wish to avoid the full-on locking for performance-critical areas in our code (such as in DSP calculation loops).
= Details for Lightweight Spin Lock =
The relevant portion here:
I would not recommend using critical regions in such an instance as it could lead to undesirable dropouts, but rather some lightweight testing. For buffer~ and similar we use two flags one to prevent access inside the perform loop when being modified outside perform(b_valid), and one to prevent modification outside the perform loop while the samples are being read. We never spin inside the perform loop if the buffer is not valid.
Example code from index~ perform routine at bottom.
We don't do things exactly like this, but we should look at how this compares to how we do actually do things. In Max 5 the above is not relied up, and instead there is the use of macros ATOMIC_INCREMENT and ATOMIC_DECREMENT which are used instead. This is perhaps what we should actually do too?