<!--
{
  "documentType" : "article",
  "framework" : "AudioToolbox",
  "identifier" : "/documentation/AudioToolbox/adding-audio-unit-auxiliary-real-time-threads-to-audio-workgroups",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Adding Audio Unit Auxiliary Real-Time Threads to Audio Workgroups"
}
-->

# Adding Audio Unit Auxiliary Real-Time Threads to Audio Workgroups

If your Audio Unit plug-in creates auxiliary real-time rendering threads, add them to the host app’s audio workgroup so the system can schedule them appropriately.

## Discussion

Most Audio Unit plug-ins don’t need to create their own real-time threads, but some complex plug-ins do to achieve their required processing. For example, a synthesizer may need to create additional real-time rendering threads to achieve maximum polyphony. So that the system knows about these threads, join them to an audio workgroup. To know which audio workgroup to add them to, provide a render context observer.

### Provide a Render Context Observer

An [`AURenderContextObserver`](/documentation/AudioToolbox/AURenderContextObserver) is a block the Audio Unit plug-in holds that the system calls before each render request. With each request, the system passes the block an [`AudioUnitRenderContext`](/documentation/AudioToolbox/AudioUnitRenderContext) object that provides the audio workgroup of the calling context. When the context’s audio workgroup changes, join your auxiliary real-time threads to the new audio workgroup.

```objc
#import <AudioToolbox/AudioToolbox.h>
 
-(AURenderContextObserver)renderContextObserver {
 
    // Create block safe pointer to kernel.
    __block AUKernel *kernel = _kernel;
     
    /* 
    The system calls this block on the render thread, 
    immediately before any render request.
    */
    return ^ (const AudioUnitRenderContext *context) {
        if (auto renderContext = context) {
            kernel->workgroupDidChange(renderContext->workgroup);
        }
        else {
            /**
            The new workgroup may be null in the case of a nonreal-time
            render context, or a real-time thread that is not part of any
            workgroup.
            */
            kernel->removeAllWorkgroups();
        }
    };
}
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)