# MacOS AudioWorkgroup example code

**URL:** <https://forum.juce.com/t/macos-audioworkgroup-example-code/60847>\
**Category:** MacOSX and iOS\
**Created:** [April 11, 2024, 6:28pm UTC](https://forum.juce.com/t/macos-audioworkgroup-example-code/60847 "2024-04-11T18:28:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhayap](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/abhayap/32/11574_2.png) [@abhayap](https://forum.juce.com/u/abhayap)\
**Post date:** [April 11, 2024, 6:28pm UTC](https://forum.juce.com/t/macos-audioworkgroup-example-code/60847/1 "2024-04-11T18:28:27Z")

</div>

Hi, I’m trying to use the new `AudioWorkgroup` feature in JUCE. I tried following the example provided [here](https://docs.juce.com/develop/classAudioWorkgroup.html#details) but I couldn’t get it working. It’s not clear what `getWorkgroup()` should be called on. Here is the code I have so far which isn’t working. Any help would be appreciated. Thanks!

```auto
class Worker : private juce::Thread
{
public:
	Worker(int samplesPerFrame, double sampleRate)
	: Thread ("Worker Thread")
	{
		startRealtimeThread(RealtimeOptions{}.withApproximateAudioProcessingTime(samplesPerFrame, sampleRate));
	}
	 
	void run() override
	{
		juce::WorkgroupToken token;
		
		getWorkgroup().join(token);
	 
		while (wait(-1) && !threadShouldExit())
		{
			// If the workgroup has changed, rejoin the workgroup with the same token.
			if (workgroupChanged())
				getWorkgroup().join(token);
	 
			// Perform the work here
		}
	}
}

```

---

<div class="post-metadata">

**Author:** ![AdamVenn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/adamvenn/32/17023_2.png) [@AdamVenn](https://forum.juce.com/u/AdamVenn)\
**Post date:** [April 11, 2024, 10:00pm UTC](https://forum.juce.com/t/macos-audioworkgroup-example-code/60847/2 "2024-04-11T22:00:15Z")

</div>

Never done anything like this, but from reading the docs, it looks like:

1. AudioIODeviceType::createAudioIODeviceType\_CoreAudio()
2. audioIODevice.getWorkgroup()
3. follow example code you posted above
