home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / mac / programm / 13980 < prev    next >
Encoding:
Text File  |  1992-08-14  |  3.7 KB  |  86 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!camex!sunfs3!kent
  3. From: kent@sunfs3.Camex.COM (Kent Borg)
  4. Subject: Re: Creating background tasks (HELP!).
  5. Message-ID: <1992Aug13.200535.18236@sunfs3.Camex.COM>
  6. Sender: kent@camex.com
  7. Organization: Camex Inc., Boston MA
  8. References: <1992Aug13.170029.3055@qiclab.scn.rain.com>
  9. Date: Thu, 13 Aug 1992 20:05:35 EDT
  10. Lines: 74
  11.  
  12. In article <1992Aug13.170029.3055@qiclab.scn.rain.com> baer@qiclab.scn.rain.com (Ken Baer) writes:
  13. >OK, first of all, I do realize that the Mac OS does not yet support real
  14. >Multitasking (nor does MS Windows). 
  15.  
  16. Careful, thousands of people are cringing right now over the flame war
  17. you might have just touched off.  (Some people are so irresponsible.)
  18.  
  19. >But, I keep hearing about certain applications or inits that allow
  20. >programs to run in the background (like the one that allows Think C
  21. >to compile in the background).
  22.  
  23. It is pretty easy for an application to do.  In fact, it is so easy
  24. that INITs have been known to convince certain applications to do it.
  25. (To be honest, I am pretty sure Think C has always allowed some
  26. background processing, it just kept the user tied up while this went
  27. on.)
  28.  
  29. >What I want to do is allow our 3D rendering software to render in the
  30. >background to the user can use the modeller etc. while rendering.
  31. >Could someone either post, or point me to some documented code to set
  32. >this up?
  33.  
  34. Look in Inside Macintosh Volume VI or the new "Processes" volume of
  35. Inside Macintosh for details, but in general, there are two things to
  36. do:
  37.  
  38. 1) When your code gets CPU time (you will know this because it is
  39. executing) do your thing.
  40.  
  41. 2) When the user decides to say something to your running code--for
  42. example canceling the rendering he mistakenly started--notice the
  43. "Stop" menu choice, or "Cancel" button, or command-period keystroke,
  44. and act on it (by stopping in this case).  
  45.  
  46. Because this is a user-oriented machine which is valuable precisely
  47. for its user interface, be very responsive about noticing that the
  48. user is talking to you.  Don't make the user pound on the keyboard.
  49. To notice that the user is talking, call GetNextEvent(), and act on
  50. anything you hear.  (Or call WaitNextEvent() if you are just sitting
  51. around waiting for something to happen.)
  52.  
  53. Oh, and don't do anyThink stupid like putting up a traditional modal dialog
  54. box.  It will prevent the user from switching to another layer.  Use a
  55. regular window or a newer movable modal dialog instead.
  56.  
  57. Simple.  You are done.  You have written a program which is responsive
  58. to the user and it is happily multitasking.
  59.  
  60. Okay, this does mean that inside your tight loops you need to notice
  61. the passage of time and occasionally check for user input.  (Do this
  62. several times a second--and possibly be clever and calibrate this at
  63. runtime based on how fast my Mac can run your loop.)  But what do you
  64. expect of an 8-plus-year-old architecture which started out in 128K of
  65. unprotected RAM??  Don't get greedy.
  66.  
  67. The secret: Everytime you call GetNextEvent() or WaitNextEvent() the
  68. system potentially offers execute time to other applications.
  69. Everytime the other applications call one of those routines you
  70. potentially get execute time.  Coopertive multitasking does require
  71. cooperation but it makes for a very user-responsive system when folks
  72. do cooperate.  It is what Modern True Real Time Multitasking Operating
  73. Systems very often do--honest.
  74.  
  75.  
  76. Make Sense?  If not, say so and there will be lots of helpful advice
  77. coming your way--but PLEASE avoid fighting words like "Real
  78. Multitasking" in future postings.
  79.  
  80.  
  81. --
  82. Kent Borg                                   kent@camex.com or kentborg@aol.com
  83.                                             H:(617) 776-6899  W:(617) 426-3577
  84. As always, things look better when some costs are left out.
  85.                               -Economist 3-28-92 p. 94
  86.