• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Suspend/resume change the IO thread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Suspend/resume change the IO thread
      • From: "Paul Sanders" <email@hidden>
References: 
 >Suspend/resume change the IO thread (From: Stéphane Letz <email@hidden>)

  • Prev by Date: Re: kIOAudioControlUsagePassThru equivalent on the iPhone
  • Next by Date: I need help arbitrating between multiple audio players in the same iPhone app
  • Previous by thread: Suspend/resume change the IO thread
  • Next by thread: Re: Suspend/resume change the IO thread
  • Index(es):
    • Date
    • Thread