Re: Accessing user interface from ioProc
Re: Accessing user interface from ioProc
- Subject: Re: Accessing user interface from ioProc
- From: Kurt Revis <email@hidden>
- Date: Wed, 19 Nov 2003 23:21:57 -0800
On Wednesday, November 19, 2003, at 08:09 PM, Michael Bonnice wrote:
In my application, I listen to the input device and calculate an FFT
all within my ioProc. This works, and I can print the results using
fprintf(stderr, ...) from my ioProc. Now I'm ready to put the results
into my user interface.
This is an Objective-C program, and I'm new to Objective-C and Cocoa.
Naturally, before I've even got the grip of the object hierarchy and
the flow of control, I need to send a message to an object while in an
ioProc, and I don't know what scope the ioProc is in (or if this is
even a meaningful concept?)
[def->leftFreqField setDoubleValue: leftFreq]; // display
the result !!!!!!!!!!!!!! problem here !!!!!!!!!!
Your ioProc is running in a separate thread from your application's
main thread. You generally should change the UI in the main thread
only, not other threads. (This is only a rule of thumb, not an ironclad
rule -- but it's a pretty good first approximation to the truth.)
You probably want to use
-performSelectorOnMainThread:withObject:waitUntilDone: to cause
something to happen in the mail thread. So for instance:
[def->leftFreqField performSelectorOnMainThread:
@selector(setObjectValue:) withObject: [NSNumber numberWithDouble:
leftFreq] waitUntilDone: NO];
2003-11-19 21:05:44.854 Tuner[466] *** _NSAutoreleaseNoPool(): Object
0x36b3d0 of class NSCFNumber autoreleased with no pool in place - just
leaking
This is because there is no NSAutoreleasePool created for you in the
ioProc thread. You need to create your own if you are going to
autorelease something (or call something that might autorelease
something).
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
// do your work here
[pool release];
In the long term, you should investigate using a lower-overhead way of
communicating between threads -- you can do it without allocating
objects or memory, or doing anything else which might block the I/O
thread. But in the short term, the stuff above will get you started.
--
Kurt Revis
email@hidden
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.