Re: ObjC Garbage Collector and MIDI Thread
Re: ObjC Garbage Collector and MIDI Thread
- Subject: Re: ObjC Garbage Collector and MIDI Thread
- From: Jeff Moore <email@hidden>
- Date: Thu, 15 Jul 2010 09:48:05 -0700
Garbage Collectors have to block threads in order to collect on them. These blocks are typically short, but there are no guarantees on an upper bound for how long they may delay the thread in question. This is completely anathema to real time operations. The best possible case is that you will have bad timing. The worst case is that you will lose data as deadlines get missed.
Not to mention the fact that your code does not own the threads in question. They can and will die and respawn at the behest of the MIDI system. So, you always run the risk of having a new thread come along and call one of your callbacks in a non-collected thread.
This is why we don't recommend using GC or anything that touches GC'd memory on the various real time contexts.
--
Jeff Moore
Core Audio
Apple
On Jul 15, 2010, at 7:10 AM, Camille Troillard wrote:
> I am working on a Cocoa application that runs on Mac OS X 10.5 and
> 10.6, and needs to receive MIDI packets. The timing accuracy does not
> need to be super precise and no audio is produced, therefore the use
> of the garbage collector appears to be a very interesting option.
>
> When the first MIDI packet is received, a GC warning is logged saying
> that the current (MIDI) thread has not been registered with the
> garbage collector. I have filled a bug report to say that this thread
> should be registered automatically with the GC if it is in use. The
> answer I got was that neither Objective-C, CoreFoundation, and
> obviously garbage collection should be used in the MIDI thread because
> of the real time constraints imposed by CoreMIDI.
>
> I first tried to find a workaround by making sure that the code was
> making no allocations. Unfortunately, every solutions I tried are
> ultimately making a call to the garbage collector.
>
> Luckily, I found a piece of code in the FireWire library
> (http://www.opensource.apple.com/source/IOFWDVComponents/IOFWDVComponents-199.4.1/DVLib.c)
> that registers the current thread with the garbage collector via a
> call to objc_registerThreadWithCollector(), which is a public API on
> 10.6 and private on 10.5. Everything seems to be working great, and
> the warning log is gone as expected.
>
> My question is the following: is there a reason why I wouldn't want
> to do that? Am I overlooking something obvious? Using the garbage
> collector in this application is a real bonus.
_______________________________________________
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