home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 January: Mac OS SDK / Dev.CD Jan 00 SDK1.toast / Development Kits / Mac OS / Multiprocessing 2.0 SDK / Documentation / Multiprocessing FAQs < prev    next >
Encoding:
Text File  |  1999-08-30  |  12.1 KB  |  313 lines  |  [TEXT/MSIE]

  1. <!--This file created 8/3/99 8:31 PM by Claris Home Page version 2.0-->
  2. <HTML>
  3. <HEAD>
  4.    <TITLE>Multiprocessing FAQs</TITLE>
  5.    <META NAME=GENERATOR CONTENT="Claris Home Page 2.0">
  6. <X-CLARIS-WINDOW TOP=52 BOTTOM=561 LEFT=118 RIGHT=648><X-CLARIS-TAGVIEW MODE=minimal>
  7. </HEAD>
  8. <BODY BGCOLOR="#99CCFF">
  9.  
  10. <H1><CENTER>Multiprocessing API - Frequently Asked Questions
  11. </CENTER></H1>
  12.  
  13. <P><CENTER>Last updated: 8/03/99</CENTER></P>
  14.  
  15. <P> </P>
  16.  
  17. <H2>What is multiprocessing and multitasking?</H2>
  18.  
  19. <P>Multiprocessing is the use of more than one processor (CPU)
  20. simultaneously. By definition only a machine with more than one CPU
  21. is capable of multiprocessing. Multitasking allows multiple streams
  22. of execution to be created even if there is only a single CPU. The MP
  23. API implements a multiprocessing and multitasking environment. Any
  24. number of streams of execution can be created and one stream per CPU
  25. can be executing at any particular instant in time. Each stream of
  26. execution is called a task. Having concurrent tasks working on parts
  27. of some job, e.g. a ray trace, an image filter, a fractal etc., can
  28. reduce the overall time it takes to complete the job.</P>
  29.  
  30. <P> </P>
  31.  
  32. <H2>What is the MP API?</H2>
  33.  
  34. <P>The MP API allows a programmer to create tasks and to establish
  35. communication between them and the main application's cooperative
  36. task. A small number of other services are also available. The
  37. Multiprocessing.pdf document describes these services in detail.</P>
  38.  
  39. <P> </P>
  40.  
  41. <H2>What is the Multiprocessing API Library?</H2>
  42.  
  43. <P>The Multiprocessing API Library is a shared library that provides
  44. the services defined in the MP API. The Multiprocessing API Library
  45. communicates with the integrated task scheduling facilities and other
  46. task related issues. The library and its associated files are usually
  47. installed in the extensions folder.</P>
  48.  
  49. <P>NOTE: As of the Mac OS 8.6, the Multiprocessing API Library has
  50. been intergrated into the system file and no longer ships as a
  51. seperate library to be installed in the extnesions folder</P>
  52.  
  53. <P> </P>
  54.  
  55. <H2>Why am I getting an "out of memory" warning after the Finder
  56. starts?</H2>
  57.  
  58. <P>If you get this message, you are running with the old v1.4
  59. Multiprocessing API Library. The new integrated v2.0 library has
  60. eliminated the out of memory problems. It is no longer necessary to
  61. modify the Code Warrior extension MetroNub to increase its memory
  62. requirements.</P>
  63.  
  64. <P> </P>
  65.  
  66. <H2>What can tasks do?</H2>
  67.  
  68. <P>In general tasks can execute any function accessible by your
  69. application. Tasks created using the MP API have the ability to
  70. access main memory allocated by any tasks created by the main
  71. application and to communicate with other tasks as well as the
  72. application. Tasks must adhere to the restrictions outlined below.
  73. </P>
  74.  
  75. <P> </P>
  76.  
  77. <H2>What are the restrictions on tasks and the application?</H2>
  78.  
  79. <P>Tasks must not execute 68k code. Attempting to do so by calling
  80. through a UPP that entails a mixed mode switch to 68k will cause the
  81. task to be terminated.</P>
  82.  
  83. <P>Tasks must not call the Macintosh Toolbox directly. Tasks can
  84. access toolbox functions via the MPemoteCallfunction.</P>
  85.  
  86. <P>The application must not make MP API calls at interrupt time or
  87. from within a deferred task other than those specifically defined as
  88. interrupt-safe in the MP API documentation. Note that deferred tasks
  89. are defined in the Deferred Task Manager, they are not an MP API
  90. related concept.</P>
  91.  
  92. <P> </P>
  93.  
  94. <H2>How are tasks run?</H2>
  95.  
  96. <P>Preemptive tasks, along with the Mac OS (blue) task, are inserted
  97. into a scheduling queue and are assigned to available processors.
  98. Tasks run preemptively. They run for a certain amount of time after
  99. which they will be interrupted and returned to the end of the
  100. scheduling queue. This way all tasks in the system can be assured
  101. fair access to the available processors. Tasks can also voluntarily
  102. return themselves to the scheduling queue using the MPYield() call.
  103. When a task blocks on one of the resource objects, and that resource
  104. is not available, the task is immediately suspended and the next task
  105. on the scheduling queue is run. Suspended tasks are not returned to
  106. the scheduling queue until the object on which they are waiting
  107. becomes available. Suspended tasks incur no system overhead.</P>
  108.  
  109. <P> </P>
  110.  
  111. <H2>How many tasks should I create?</H2>
  112.  
  113. <P>The number of tasks an application can create is not logically
  114. limited. Most applications will want to limit the creation of tasks
  115. that perform a given function to the number of available processors.
  116. As long as there are at least as many tasks performing work as there
  117. are available processors, maximum advantage of the system will be
  118. taken. Some problems are best decomposed into a fixed number of
  119. tasks, regardless of the number of processors. It is sometimes useful
  120. to have the main application perform some of the work also. This is
  121. especially true in applications that do not require the
  122. Multiprocessing API Library to be present. In this case the optimum
  123. number of tasks to create is the number of processors.</P>
  124.  
  125. <P> </P>
  126.  
  127. <H2>Do I need a multiprocessing system to use the MP API?</H2>
  128.  
  129. <P>No. The Multiprocessing API Library is always available. This
  130. means that you can create preemptive tasks on a PowerPC platform,
  131. provided those tasks adhere to the restrictions described above.</P>
  132.  
  133. <P> </P>
  134.  
  135. <H2>What special tools do I need for development?</H2>
  136.  
  137. <P>You continue to use the same development tools you have always
  138. used. There are no special compilers or linkers to be used. All you
  139. add is a header file, Multiprocessing.h, to your source code then
  140. include the MPLibrary.stub file in your linker library list.</P>
  141.  
  142. <P> </P>
  143.  
  144. <H2>How do I debug this stuff?</H2>
  145.  
  146. <P>Macsbug is capable of debugging tasks much in the same way as it
  147. debugs within Mac itself. In addition, the MP API has debugging
  148. functions that let you write a high level debugger. <I>Metrowerks has
  149. an MP debugger that needs to be qualified in this release.</I></P>
  150.  
  151. <P> </P>
  152.  
  153. <H2>How can I test MP-savvy applications?</H2>
  154.  
  155. <P>Apple recommends testing the MP-savvy applications on two
  156. platforms: a uniprocessor Macintosh and a multiprocessor Macintosh.
  157. The application code can be identical in both cases, but the
  158. application may have dependencies or race conditions that are only
  159. visible on a multiprocessor system.</P>
  160.  
  161. <P> </P>
  162.  
  163. <H2>When can I get started?</H2>
  164.  
  165. <P>You can start now. The Multiprocessing API Library and
  166. multitasking enabler included on this disk is the final product. It
  167. will allow you to create and test applications on uniprocessor
  168. systems that will run without modification on real multiprocessing
  169. systems (assuming no programming errors of course).</P>
  170.  
  171. <P> </P>
  172.  
  173. <H2>When will hardware be available?</H2>
  174.  
  175. <P>Hardware is available now in 9500/180MP systems and DayStar
  176. Genesis 2-P systems. Other system configurations will be available
  177. soon.</P>
  178.  
  179. <P> </P>
  180.  
  181. <H2>How will supporting the MP API impact my source base? What about
  182. 68K?</H2>
  183.  
  184. <P>The MP API cannot be used on 68k machines. You can have a single
  185. source base but the 68k side will not be able to create preemptive
  186. tasks -it should behave as though the Multiprocessing API Library is
  187. not present. The PowerPC side should also be able to handle the
  188. situation where the Multiprocessing API Library is not present even
  189. though it is now a permanent part of the system. This retains
  190. backward compatibility. The same code can thus be used for both
  191. situations.</P>
  192.  
  193. <P>If an application requires PowerPC and is also willing to require
  194. the presence of the Multiprocessing API Library, then tasks can be
  195. created and executed regardless of the number of processors in the
  196. system. Tasks created by an application are distributed preemptively
  197. amongst the available processors, even if there is only one, so
  198. task-creating code will work on any type of PowerPC system.</P>
  199.  
  200. <P> </P>
  201.  
  202. <H2>What will happen to the MP API when Carbon API ships?</H2>
  203.  
  204. <P>The MP API will run on all current and planned generations of the
  205. PowerPC-based Mac &emdash;namely, Mac OS 8, the Carbon API under Mac
  206. OS 8, and in Mac OS X.</P>
  207.  
  208. <P> </P>
  209.  
  210. <H2>How are the MP API and the Thread Manager related?</H2>
  211.  
  212. <P>MP tasks are preemptive execution streams, and are implemented as
  213. kernel tasks in Mac OS 8 and Mac OS X. The task and thread APIs will
  214. remain different.</P>
  215.  
  216. <P>The Thread Manager API will definitely be supported in Mac OS 8
  217. and Mac OS X, but there are no plans to extend it. Threads will
  218. continue to have the same cooperative scheduling model. Threads are
  219. not the path to preemptive scheduling or multiprocessor support in
  220. Mac.</P>
  221.  
  222. <P> </P>
  223.  
  224. <P>We are recommending that developers use the MP API to write
  225. applications that wish to take advantage of preemptive scheduling and
  226. multiprocessors, both on Mac OS 8 and Mac OS X. This API is fully
  227. supported in Mac OS 8, and beyond. It has been designed to map
  228. naturally into the Mac OS X tasking model. In Mac OS 8 and Mac OS X,
  229. MP tasks become identical to kernel tasks, The MP APIs become thin
  230. layers of glue mapping them into kernel calls.</P>
  231.  
  232. <P>The "MP" API is probably misnamed because it is supported on all
  233. Power Macintosh systems, both uniprocessor and multiprocessor. An
  234. application written to the MP API will automatically take advantage
  235. of all processors that are available. On uniprocessor systems, MP
  236. tasks behave like preemptive tasks.</P>
  237.  
  238. <P> </P>
  239.  
  240. <H2>Where can I find examples?</H2>
  241.  
  242. <P>In this SDK! </P>
  243.  
  244. <H2>How can I communicate with a task at interrupt time or from
  245. within a deferred task?</H2>
  246.  
  247. <P>With the v2.0 integrated multitasking support, communication can
  248. be achieved by simply using the SetEvent, SignalSemaphore, or
  249. MPNotifyQueue functions. The SetEvent and SignalSemaphore functions
  250. are always interrupt safe. MPNotifyQueue becomes interrupt safe when
  251. the subject queue has had notifications reserved for it. See
  252. MPSetQueueReserve in the MP API documents for details.</P>
  253.  
  254. <P>The rest of the Multiprocessing API Library is not interrupt safe
  255. and any attempt to call it at interrupt time or deferred task time
  256. will potentially cause a crash.</P>
  257.  
  258. <P> </P>
  259.  
  260. <H2>What kind of problems can I expect from tasks sharing memory?
  261. </H2>
  262.  
  263. <P>Tasks should be careful about what memory they modify -it is not
  264. polite to modify memory being used by another task without
  265. communicating that fact to the other task. Modifying globals from
  266. within a task, or buffers pointed to by global variables should be
  267. avoided.</P>
  268.  
  269. <P>Tasks must not attempt to modify memory outside of the application
  270. address space. Although implementations may vary, the model is that
  271. each application runs in its own address space. The application's
  272. cooperative task (and threads), and any preemptive tasks created by
  273. the application share the same address space. Although the current
  274. Mac OS 8 implementation has all applications running in a global
  275. address space, this may change at any time. Applications that expect
  276. to run unchanged in Mac OS X must not violate the memory model.</P>
  277.  
  278. <P> </P>
  279.  
  280. <H2>I crash after calling MPTerminateTask(). Why?</H2>
  281.  
  282. <P>MPTerminateTask() does not terminate a running task immediately.
  283. The task may continue to run for a short time while termination
  284. proceeds asynchronous to the MPTerminateTask call. Normal application
  285. cleanup techniques involve terminating all the tasks owned by the
  286. application and then disposing of all the semaphores, queues, memory,
  287. etc. that the tasks were using. Since the task doesn't really stop
  288. running straight away it starts using invalid data as the application
  289. starts deleting the shared resources. This can lead to catastrophic
  290. crashes. The proper way to avoid this situation is to provide a
  291. termination queue when you create a task, and wait on the queue
  292. immediately after terminating the task. Once something is received
  293. you can be sure that the task is no longer running. Alternatively
  294. your application can notify a task that it is about to be terminated
  295. and wait for the task to acknowledge the notification. The task
  296. should not use any more shared resources after it sends the
  297. acknowledgment.</P>
  298.  
  299. <P> </P>
  300.  
  301. <H2>How do I get support for the MP API?</H2>
  302.  
  303. <P>Apple computer is providing support for the MP API. You can
  304. contact Apple at dts@apple.com .</P>
  305.  
  306. <P> </P>
  307.  
  308. <P> </P>
  309.  
  310. <P>Copyright © Apple Computer, Inc.</P>
  311. </BODY>
  312. </HTML>
  313.