Threading/timer issues on Mach-O vs. OS 9
Threading/timer issues on Mach-O vs. OS 9
- Subject: Threading/timer issues on Mach-O vs. OS 9
- From: Stephen Kay <email@hidden>
- Date: Sun, 23 Apr 2006 16:43:51 -0400
Apologies if this is not the right list, but someone at carbon-dev suggested
I ask here, as this list deals with music processing apps a lot.
I'm porting a Classic app to OSX. It was done originally in PowerPlant. I'm
confused on a number of levels, about Mach-O threading/timers, and how it
relates to some issues I'm experiencing porting this app.
I think I was using what was a pretty common method of
creating a scheduler:
There is a 1 ms callback installed as a Timer function (i.e. using
NewTimerUPP() and InsXTime()). So I'm getting 1ms interrupts, and having it
process a list of queued tasks stored in a linked list according to
execution time (the "ScheduledQueue") - for my purposes, this is used to
generate MIDI data in real-time to create algorithmic music. (I guess this
is what is known as a preemptive thread?)
There's another queue of tasks, the "DeferredQueue", that is *NOT* performed
at interrupt level, such as redrawing blinking leds, GUI updating, etc. This
tasklist is processed by the app's "idle time" mechanism, whenever it's not
busy. (I guess this is the main app thread?) I can find nothing in
PowerPlant related to threading, so I guess it's just one thread within the
main event loop, i.e. LApplication::Run()).
There is a mechanism to set a "lockoutFlag" around "critical sections" of
code that you don't want interrupted for any reason. The lockout flag
prevents interrupts while it is set to true. Both types of functions
above are able to set and unset this flag, referring of course to the
previous state when setting and unsetting.
In OSX, it appears that sometimes, this flag is getting stuck in the locked
position, at which point the execution of the music generation stops.
My guess is that the execution of the DeferredQueue that handles GUI
updating etc. (the main app thread) is able to be interrupted by the Mac OSX
at any time (in a different way than what happens on OS9). So the main
thread apparently suspends activity while in the middle of redrawing, leaves
the lockoutFlag set to true, and then the interrupt level thread cannot
perform any more tasks. And the status of the flag somehow gets confused. Or
something like that. Or maybe not.
1. Does anybody know what I'm talking about? ;-)
2. I don't even know what kind of threading this is, now that its on Mach-O.
I don't see "NewThread" being called anywhere in PowerPlant, and the only
thing I'm doing is installing the TimerProc. I've tried reading the
technote2028 that compares OS9 and OSX threading, and it's a pretty high
level of greek (or is that geek) to me. Same with the Thread Manager
reference. I'm not even sure what level of threading/tasking I was using, or
now am using since I ported my app to mach-O. I never really worried about
it much before. It just worked. ;-)
3. On another front, I see that this whole method of doing things has been
deprecated (or has it?). The Time Manager Reference says "Deprecated. Use
Carbon Event Loop timers or Cocoa NSTimers instead." I was checking out the
discussion of "InstallEventLoopTimer()" - is this going to have the same 1ms
accuracy as the other way of doing it? The Carbon Event Manager Reference
says about it "IT executes at task level and should not be confused with
Time Manager tasks or any other interrupt-level callback." I'm confused
about what I need to do here...
I'd prefer to rewrite as little of this as possible. It almost works, except
for this lockout flag getting "stuck".
Thanks for any tips,
- Stephen
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Stephen Kay
Karma Lab - developers of KARMA
http://www.karma-lab.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
_______________________________________________
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