Re: How to safely remove an IOProc
Re: How to safely remove an IOProc
- Subject: Re: How to safely remove an IOProc
- From: Jeff Moore <email@hidden>
- Date: Sun, 07 Feb 2010 15:34:46 -0800
If you note, this crash is at an address without a symbol. This likely means that either the destination of the jump was bad or could also mean that the stack itself were corrupt. This is indicative of something operating on deallocated/corrupted memory. My guess is that there is more to the picture than just the code you've listed below. Something your IOProc is touching or even the IOProc itself has been deallocated too early.
Note that there is no guarantee about how many times your IOProc might get called after AudioDeviceStop() returns when you make the call from outside of your IOProc. However, if you call AudioDeviceStop() from inside your IOProc, you do get the guarantee that your IOProc will not get called again after the IOProc has returned.
That said, the code you posted is not going to work correctly if there are two IOProcs on the device, which can happen under lots of circumstances, especially if you are using multiple APIs like NSSound, QT, etc. Also, kAudioDevicePropertyDeviceIsRunning is a global property. It's value will be the same regardless of the value of the inIsInput argument to AudioDeviceGetProperty(). It also seems like if any of the API calls ever returned an error, that bad things might happen too. Presumably, this is just because it is a simplification of what your real code is doing.
Finally, you should consider migrating your code away from deprecated APIs like AudioDeviceGetProperty() and AudioDeviceRemoveIOProc.
On Feb 7, 2010, at 11:41 AM, Paul Sanders wrote:
> Hi folks,
>
> I'm a little confused about how to safely shut down a running device and remove my IOProc. I currently have code that looks like this:
>
> OSStatus status = AudioDeviceStop (my_device, MyIOProc);
> while (status == noErr)
> {
> UInt32 device_running = 0;
> UInt32 nbytes = sizeof (device_running);
> status = AudioDeviceGetProperty (my_device, 0, true,
> kAudioDevicePropertyDeviceIsRunning, &nbytes, &device_running);
> if (status != noErr || !device_running)
> {
> status = AudioDeviceGetProperty (my_device, 0, false,
> kAudioDevicePropertyDeviceIsRunning, &nbytes, &device_running);
> if (status != noErr || !device_running)
> break;
> }
> SleepForMilliseconds (50); // rare, if ever
> }
> status = AudioDeviceRemoveIOProc (my_device, MyIOProc);
>
> This seems to work fine on all my test machines, but I have one or two reports from the field of crashes that look like this:
>
> Thread 12 Crashed:
> 0 ??? 0x031c3070 0 + 52179056
> 1 com.apple.audio.CoreAudio 0x983005b4 HP_IOProc::Call(AudioTimeStamp const&, AudioTimeStamp const&, AudioBufferList const*, AudioTimeStamp const&, AudioBufferList*) + 374
> 2 com.apple.audio.CoreAudio 0x9830031a IOA_Device::CallIOProcs(AudioTimeStamp const&, AudioTimeStamp const&, AudioTimeStamp const&) + 370
> 3 com.apple.audio.CoreAudio 0x98300116 HP_IOThread::PerformIO(AudioTimeStamp const&, double) + 620
> 4 com.apple.audio.CoreAudio 0x982fd4fa HP_IOThread::WorkLoop() + 2506
> 5 com.apple.audio.CoreAudio 0x982fcb2b HP_IOThread::ThreadEntry(HP_IOThread*) + 17
> 6 com.apple.audio.CoreAudio 0x982fca42 CAPThread::Entry(CAPThread*) + 140
> 7 libSystem.B.dylib 0x98442fbd _pthread_start + 345
> 8 libSystem.B.dylib 0x98442e42 thread_start + 34
>
> In once case (on a customer's machine to which I have no access) I am told that this is 100% reproducible when shutting down the device. He has a Griffin iMic, Snow Leopard 10.6.2 and a quad core MacPro, but I have tested with an iMic on my 2009 dual core MacBook and it works fine.
>
> So, what am I doing wrong?
>
> Many thanks,
>
> Paul Sanders.
>
> _______________________________________________
> 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
--
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