• 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: terminating thread operation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: terminating thread operation


  • Subject: Re: terminating thread operation
  • From: Jeff Moore <email@hidden>
  • Date: Thu, 10 Apr 2008 21:55:03 -0700


On Apr 10, 2008, at 6:30 PM, Roland Silver wrote:
I have an app that runs two threads that I've created: a main thread, and one that the CoreAudio code runs in, including a callback. The CoreAudio framework stuff presumably runs in a third thread (but maybe not).

The HAL will manage all the IO threads. There is no way to override this behavior.

But you can tell the HAL what thread to use for notification handling via the system object property, kAudioHardwarePropertyRunLoop. If you don't explicitly set this property, the HAL will spawn and manage it's own thread for the job.
The main thread creates the second thread by invoking NSThread > detachNewThreadSelector. The second thread begins generating sound by calling CFRunLoopRun.

There's a little more to generating sound than just calling CFRunLoopRun =)
In writing my code, I assumed that the second thread could be terminated by calling CFLoopStop(CFLoopGetCurrent()) from code executing within the second thread, but that doesn't work.



There are two things to keep in mind here. First, every thread has a run loop. Second, calling CFRunLoopGetCurrent() will return a reference to the run loop of the thread you are running on at the time. Thus, calling CFRunLoopStop(CFRunLoopGetCurrent()) on Thread A will not cause Thread B's run loop to stop. Rather, it will cause A's run loop to stop.

Given all that, if you want Thread A to manipulate Thread B's run loop, Thread B has to arrange to make a reference to it's run loop available somehow. Usually this is done by having Thread B call CFRunLoopGetCurrent() early in it's life and storing the reference somewhere where Thread A can get at it, like a global variable or something like that.


--

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
References: 
 >terminating thread operation (From: Roland Silver <email@hidden>)

  • Prev by Date: Re: terminating thread operation
  • Next by Date: Re: Meta Parameters
  • Previous by thread: Re: terminating thread operation
  • Next by thread: built-in (DLS) equivalent of QTMA instruments?
  • Index(es):
    • Date
    • Thread