Re: Suspend/resume change the IO thread
Re: Suspend/resume change the IO thread
- Subject: Re: Suspend/resume change the IO thread
- From: Jeff Moore <email@hidden>
- Date: Wed, 26 May 2010 12:53:04 -0700
On May 26, 2010, at 7:35 AM, Stéphane Letz wrote:
> We need to call some code *once* in the IO thread (to setup up a pthread_key_t thread local stuff...). Until now we were using a second IO callback to be added and started (AudioDeviceAddIOProc and AudioDeviceStart) and that was just removing itself (AudioDeviceStop..;) after being called.
On the surface, this seems fragile by itself as the HAL doesn't guarantee the order in which IOProcs are called. But presumably, you've dealt with that issue since that's not what you are asking about =)
> We have just seen that the IO thread identifier (the one got with pthread_self()) is changed when the machine is suspended/resumed. So our init code is not properly called anymore when the IO thread resume.
That's not the only case this will happen in either. For example, if the device changes formats, IO is stopped and restarted around the HAL doing it's bookkeeping.
> Is there any cleaner and more reliable way to call some code once in the IO thread and properly handle the suspend/resume case? (like some notification to be listened to) ?
The IsRunning notification is always delivered from on the IO thread. It is also always delivered prior to when the HAL starts calling IOProcs. The catch is that you won't get an IsRunning notification if the IO thread had already been running prior to when you started your IOProc.
That said, the most reliable way to do it, IMHO, is to just be lazy about it and do the initialization in the IOProc the first time you notice that the thread local data isn't initialized. This seems too obvious though. Is there a reason that you can't do it this way such that you need to initialize things outside of your real IOProc?
--
Jeff Moore
Core Audio
Apple
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden