Threads


A thread is a single sequential flow of control within a process. Threads are the basis for multithreaded programs, which allow a single program to control concurrently running threads, each performing a different task. Multithreaded programs generally use reentrant code (code that multiple threads can use simultaneously) and are most valuable when run on multiple-CPU machines. Under Mac OS X, multithreaded servers can provide a cleaner interface and may be easier to write than multiple server processes. When applied judiciously, multithreading can also serve as a lower-overhead replacement for the traditional fork-exec idiom for spawning processes. Documentation for threads includes the pthread man page (for the C interface) and the NSThread class documentation (for Objective-C). For more general information about threads, see the FAQ at tldp.org/FAQ/Threads-FAQ.

Tip: Multiple threads are not always better

If you write a multithreaded program with no clear goal or division of effort for a single-CPU system (for example, a parallel-server process), the resulting program will likely run more slowly than a nonthreaded program on the same system.





A Practical Guide to UNIX[r] for Mac OS[r] X Users
A Practical Guide to UNIX for Mac OS X Users
ISBN: 0131863339
EAN: 2147483647
Year: 2005
Pages: 234

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net