Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!apple!lsr From: lsr@Apple.COM (Larry Rosenstein) Newsgroups: comp.sys.mac.programmer Subject: Re: Questions about multitasking on the mac Message-ID: <13485@goofy.Apple.COM> Date: 14 May 91 17:19:14 GMT References: <1991May11.191114.27564@potomac.ads.com> Organization: Apple Computer, Inc. Lines: 44 In article <1991May11.191114.27564@potomac.ads.com> jtn@potomac.ads.com (John T. Nelson) writes: > >This means that I don't get to call WaitNeXTEvent and thus the >foreground process has total control. No backgrounding possible >because we don't get to the event loop until complete. You can always yield the CPU by calling WaitNextEvent with a null mask. This will give background tasks a chance to run. Since you pass a null mask, you won't get back any events, and the user won't be able to put your app in the background. If you want to be able to run in the background, then have to do more work. You will have to use a non-null mask, and actually process any events that you receive. You will also have to filter out events/actions that don't make sense while your program is running. >I suppose this can be done but its GROSS infusing this event code in >every module to get timely event updates. I can't figure out a better One solution if you are using MPW 3.2 (don't know about THINK C) is to take advantage of the new -trace on flag. This was added to correspond to the feature in MPW Object Pascal. What it does is insert call to %_BP and %_EP at the beginning and end of each routine. You can then use the linker's ability to rename modules to direct these calls to a routine that handles the events. If your program does a lot of procedure calls, this may be sufficient. Otherwise, you might have to manually insert additional calls in other loops. It's also possible to mechanically insert calls in all the loops. Another thing you should do is record the time between calls to this routine, and only call WaitNextEvent if sufficient time has elapsed. Calling WaitNextEvent more frequently simply slows down your application, without improving the system's responsiveness. I've used this technique to port the PBMPLUS image processing package to MPW, and get it to run well in the background. In that environment, you can even use shell variables to control how often the program yields the CPU. -- Larry Rosenstein, Apple Computer, Inc. lsr@apple.com (or AppleLink: Rosenstein1)