# develop-06 9104 Spring 1991 — source transcripts, page 1

[Canonical transcript page](https://www.vintageapple.net/transcripts/media/va-develop-06-9104-spring-1991-8d7fb4/1)

## Transcribed source material

Machine transcriptions and image descriptions; uncertain copy may be marked [illegible]. Verify against the linked originals. Historical rights remain with the original owners.

These are transcribed excerpts, not the full publications. Open the originals for remaining pages.

### Image 1

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-06-9104-spring-1991-8d7fb4/1#scan-7cf5bbbd011c4301afe0c9e84747fd7654520c7e43c02db9e92175838a1db4ef)

Transcribed text:

develop
The Apple Technical Journal

THREADS ON THE MACINTOSH

QUICKDRAW'S COPYBITS PROCEDURE: BETTER THAN EVER IN SYSTEM 7.0

MACTCP COOKBOOK: CONSTRUCTING NETWORK-AWARE APPLICATIONS

A FAMILIAR (INTER)FACE

COLOR PRINTING WITH LASERWRITER 6.0 REVISITED

MACINTOSH Q & A

APPLE II Q & A

YOUR DEVELOPER ESSENTIALS DISC (NOW WITH CODE SNIPPETS)

Issue 6 Spring 1991
Apple Computer, Inc.

Image description: The cover shows a colorful wireframe grid illustration with curving pink, orange, and yellow lines on a dark teal background, with the masthead and a column of bold article titles on the right.

Reading notes: Masthead 'develop' is stylized lowercase with wide letter spacing; treated as the headline. Article titles are in a right-hand column and read top to bottom. Issue number '6' and 'Spring 1991' are printed on the bottom right.

Printed dates: Spring 1991

Languages: English

[Original Image 1](https://www.vintageapple.net/files/88954114d59a59cb8cb60aeb767a32d84af4f620df03042d2f846b373b15d902/515940186dae5a243436507d.webp)

### PDF page 1

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-06-9104-spring-1991-8d7fb4/1#scan-2866a5b2f61b3bfe1544347c86f4ef2c4d3f4e5ee5dbd432edeb4d77b1458238)

THREADS ON THE MACINTOSH

Transcribed text:

d e v e l o p T h e   A p p l e   T e c h n i c a l   J o u r n a l
THREADS ON THE
MACINTOSH
QUICKDRAW'S
COPYBITS
PROCEDURE:
BETTER THAN EVER
IN SYSTEM 7.0
MACTCP COOKBOOK:
CONSTRUCTING
NETWORK-AWARE
APPLICATIONS
A FAMILIAR
(INTER)FACE
COLOR PRINTING
WITH LASERWRITER
6.0 REVISITED
MACINTOSH Q & A
APPLE II Q & A
YOUR DEVELOPER
ESSENTIALS   DISC
(NOW WITH CODE
SNIPPETS)
I ssue 6   Spring 1991
Apple Computer, Inc.

Reading notes: Masthead is letter-spaced in the source ('d e v e l o p T h e   A p p l e ...'), so reading order and exact spacing are uncertain. 'I ssue 6' likely has an extraction spacing artifact and may read 'Issue 6'. Headline is ambiguous: the first cover line 'THREADS ON THE MACINTOSH' is used, but the masthead may be the primary headline. Items such as Macintosh, System 7.0, and LaserWriter 6.0 are article topics on a journal cover rather than advertised products; they are listed as distinct named items only. Parenthetical '(INTER)FACE' and '(NOW WITH CODE SNIPPETS)' are reproduced as printed in the source.

Printed product names: Macintosh · QuickDraw · System 7.0 · MacTCP · LaserWriter 6.0 · Apple II · Developer Essentials Disc

Printed dates: Spring 1991

Languages: English

[Original PDF page 1](https://www.vintageapple.net/files/55be35a2a9d841c7e1b82c2183e0dcecd3715cf688a1caceff9e91afe507c3cc/develop-06_9104_Spring_1991.pdf#page=1)

### PDF page 2

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-06-9104-spring-1991-8d7fb4/1#scan-69e2a94981ce55d2eb5b87dfe82a0f99b6428799dc56f327a5ac920fbc8e17a2)

Transcribed text:

E D I T O R I A L
Editor-in-Cheek   Caroline Rose
Spirited Guide   Louella Pizzuti
Technical Buckstopper   Dave Johnson
Managing Editor   Monica Meffert
Contributing Editors   Lorraine Anderson,
Geta Carlson, Toni Haskell, Judy Helfand,
and Rilla Reynolds
Editorial Assistant   Helen Stea
Indexer   Ira Kleinberg
Manager, Developer Technical Communications
David Krathwohl
A R T   &   P R O D U C T I O N
Production Manager   Hartley Lesser
Art Director   Diane Wilcox
Design   Joss Parsey
Technical Illustration   Don Donoughe and
Diane Wilcox
Formatting   Automatrix
Printing   Craftsman Press
Film Preparation   Aptos Post Inc.
Production   PrePress Assembly
Photographer   Ralph Portillo
Circulation Management   David Wilson
Online Production   Cassi Carpenter
Cleo Huggins created this cover with
Adobe Illustrator ® . A theoretical Klein
plane was chosen to represent the
complex topology on which threads of
execution operate.
d e v e l o p ,   The Apple Technical
Journal,   is a quarterly publication
of the Developer Technical
Communications group.

Reading notes: No headline is printed; the masthead label 'E D I T O R I A L' and 'A R T & P R O D U C T I O N' are section headings rather than a headline. The page is a credits page, not an advertisement, so no advertised products or prices are listed; 'Adobe Illustrator' and 'The Apple Technical Journal' appear only in running copy and were not treated as advertised products. No dates or years appear in the supplied copy. Layout and reading order of the staff columns could not be verified from the image, so the grouping of roles is taken from the line breaks in the extracted text.

Languages: English

[Original PDF page 2](https://www.vintageapple.net/files/55be35a2a9d841c7e1b82c2183e0dcecd3715cf688a1caceff9e91afe507c3cc/develop-06_9104_Spring_1991.pdf#page=2)

### PDF page 3

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-06-9104-spring-1991-8d7fb4/1#scan-5ff4356f82e4cfbfd979255ab45297fdb75699c4a553a44eaae6b1c2d1d7ab14)

Transcribed text:

CONTENTS   Spring 1991
1
E D I T O R I A L   2
L E T T E R S   4
A R T I C L E S
Threads on the Macintosh   by Michael Gough   Multiple concurrent threads
of execution on the Macintosh? You bet! This article presents a complete threads
package, talks about its implementation, and shows you how to use it.   6
QuickDraw‘s CopyBits Procedure: Better Than Ever in System 7.0
by Konstantin Othmer   In System 7.0, the internal workings of this versatile
routine have changed (for the better, of course!). Learn all about the differences,
and check out some simple but useful image processing techniques.   23
MacTCP Cookbook: Constructing Network-Aware Applications
by Steve Falkenburg   Networking for the rest of us. Here’s an introduction to
the TCP/IP protocol suite, and a library of routines that make using MacTCP a
(relative) breeze.   46
C O L U M N S
Print Hints from Luke & Zz: Color Printing with LaserWriter 6.0
Revisited   by Pete “Luke” Alexander   A potential color printing problem,
and some solutions. Also sharks, surfboards, and surfer dudes.   44
The Veteran Neophyte: A Familiar (Inter)face   by Dave Johnson
Chernoff faces, n-dimensional points, and simulation in the human (and canine)
interface.   70
Q   &   A
Answers to your product development questions.
Macintosh Q & A   72
Apple II Q & A   80
D E V E L O P E R   E S S E N T I A L S   86
A description of what’s old and what’s new on your   Developer Essentials   CD-ROM
disc. Code snippets are new—check ’em out!
I N D E X   90
© 1991 Apple Computer, Inc. All rights reserved.
Apple, the Apple logo, Apple IIGS, AppleLink, APDA, AppleTalk, GS/OS, HyperTalk, ImageWriter, LaserWriter,
Macintosh, MacTCP, MPW, MultiFinder, and ProDOS are registered trademarks of Apple Computer, Inc. Finder,
HyperMover, KanjiTalk, and QuickDraw are trademarks of Apple Computer, Inc. HyperCard is a registered
trademark of Apple Computer, Inc., and is licensed to Claris Corporation. PostScript is a registered trademark
of Adobe Systems Incorporated. NuBus is a trademark of Texas Instruments. UNIX is a registered trademark of
UNIX System Laboratories.
CONTENTS

Reading notes: Table of contents page numbers and some layout-dependent reading order may be unclear

Printed product names: Macintosh · MacTCP · QuickDraw · LaserWriter · Developer Essentials · Apple IIGS · AppleLink · APDA · AppleTalk · GS/OS · HyperTalk · ImageWriter · MPW · MultiFinder · ProDOS · Finder · HyperMover · KanjiTalk · HyperCard · PostScript · NuBus

Printed dates: Spring 1991 · 1991

Languages: English

[Original PDF page 3](https://www.vintageapple.net/files/55be35a2a9d841c7e1b82c2183e0dcecd3715cf688a1caceff9e91afe507c3cc/develop-06_9104_Spring_1991.pdf#page=3)

### PDF page 4

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-06-9104-spring-1991-8d7fb4/1#scan-21f81c628879ca529413558e7e8e1929bd00196ac33dee6d54d39b65f64b22ad)

LOUELLA PIZZUTI PASSES TO CAROLINE ROSE

Transcribed text:

d e v e l o p   Spring 1991
CAROLINE ROSE   has been writing computer
documentation ever since “a computer at your
fingertips” meant timesharing a mainframe. After
a seven-year digression into programming, she
returned to her first love—writing—and was given
the opportunity to document the inner workings of
a funny little computer named Macintosh. The
result was a three-volume tome that, in its hard-
cover edition, was the first technical manual to
qualify as a lethal weapon (and we don‘t mean
by boring people to death). In what proved to be
another digression, she left Apple to launch
NeXT’s documentation effort. Returning after a
five-year hiatus, she’s thrilled to be back at Apple
among friends and foe alike. For pleasure outside
of work, Caroline reads voraciously, swims
fanatically, dances, sings, plays Scrabble, hugs
her cat, and much more.
2
Dear Readers,
Starting with this issue of   develop , Louella has passed the editorial baton to yours
truly, Caroline Rose. If the name sounds familiar, it’s because you may have seen it in
the credits for   Inside Macintosh , Volumes I-III. At one point during my three-and-a-
half-year stint as the primary author and editor of that magnum opus, I interviewed
an inexperienced but delightfully cocky young woman who convinced me that she
could do as good a job as anyone of formatting the   IM   files on the Macintosh ®  (they
were created on the Apple ®  III). She was hired, and ended up being a great help to
the project as well as a great friend. You’ll also find her name in the credits: “assisted
by” none other than Louella Pizzuti.
But the time came for me to move on. I went looking for jobs and found the next
company I would work for (puns intended). After four years as that next company’s
Manager of Publications and a year as its Editor in Chief, I was ready to move on
again. I put the word out at Apple and got a phone call from Louella, with whom I
had fallen woefully out of touch over the years. Now the friendship has been
renewed and we’re working together once again—this time with her as my boss!
After a brief orientation (and a wonderful “welcome” lunch) on my first day back at
Apple, I was steered into a meeting at which I had to immediately make my first
decision as   develop ’s new Editor in Chief. Actually, it was sort of a trick question,
since everyone present had already agreed on the answer. Fortunately, I was of like
mind, and as a result we’re calling this simply Issue 6 rather than continue with the
previous issue’s use of “Volume 2” (which snuck in while Louella was out with a bad
back). So for those of you who are collecting the whole set (knowing it will be of
inestimable value someday), take note that the previous issue’s number should be
reassigned according to the following formula:
int
CalculateIssueNumber(int   Volume,   int   Issue)
{
return   ((Volume   –   1)   *   4)   +   Issue;
}
2
LOUELLA PIZZUTI
PASSES TO
CAROLINE ROSE

Reading notes: Code snippet formatting in the letter may not preserve exact reading order Headline text is printed in capitals and may differ slightly in layout from the body

Printed product names: Inside Macintosh · Macintosh · Apple III · NeXT

Printed dates: Spring 1991

Languages: English

[Original PDF page 4](https://www.vintageapple.net/files/55be35a2a9d841c7e1b82c2183e0dcecd3715cf688a1caceff9e91afe507c3cc/develop-06_9104_Spring_1991.pdf#page=4)

### PDF page 5

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-06-9104-spring-1991-8d7fb4/1#scan-b14ee8813ee76fcc906d1250443a8757c049ab35ce428b734cb10485b1a1a16f)

Transcribed text:

Or, for you Pascal types:
FUNCTION   CalculateIssueNumber   (Volume,   Issue:   INTEGER):   INTEGER;
B E G I N
CalculateIssueNumber   :=   ((Volume   -   1)   *   4)   +   Issue;
E N D ;
You may notice other changes introduced in this issue. We hope you’ll agree
they’re changes for the better; if not, be sure to let us know. Please also let us know
if you’d be interested in writing an article for   develop   yourself. Do you have any
nifty code you’d like to share with the rest of the Apple developer world? Have you
yearned to have your own silly bio grace these pages (not to mention your photo)?
Think of how pleased your mother would be to receive a copy.
I’ll leave you with a riddle: I entered this entire editorial without pressing a single
key on the keyboard or clicking the mouse button. I was as quiet as a mouse (the
furry kind). How did I do this? And furthermore, why? Stay tuned for the answer
in our next issue.
Caroline Rose
Editor
EDITORIAL   Spring1991
3 SUBSCRIPTION INFORMATION
Use the order form on the last page of this issue
to subscribe to
develop. Please address all
subscription-related inquiries to
develop, Apple
Computer, Inc., P.O. Box 531, Mt. Morris, IL
61054 (or AppleLink DEV.SUBS).•
BACK ISSUES
Back issues of
develop are available through
APDA ®  (see inside back cover for APDA
information) and are also on the
Developer
Essentials CD-ROM disc.•

Reading notes: Spacing in the printed 'Spring1991' date is ambiguous and may be a formatting artifact

Printed product names: Pascal · develop · AppleLink DEV.SUBS · APDA · Developer Essentials CD-ROM

Printed dates: Spring1991

Languages: English

[Original PDF page 5](https://www.vintageapple.net/files/55be35a2a9d841c7e1b82c2183e0dcecd3715cf688a1caceff9e91afe507c3cc/develop-06_9104_Spring_1991.pdf#page=5)

### PDF page 6

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-06-9104-spring-1991-8d7fb4/1#scan-f6f7d769b8c74c27f2878d7e57611eb83a63dc68b021d26e2136fd74cd4a6e30)

Transcribed text:

• I encountered a technical error in the
Macintosh Q & A section in the latest
issue of   develop . The question was: “Is
the maximum size for global and local
data still 32K?” The answer stated that
the 32K limit for local (stack) data “is
basically due to the Motorola processor
architecture.” As stated in the answer,
the LINK instruction is limited to a 16-
bit offset. Unstated in the answer is that
the compiler can easily work around this
limitation. Suppose your program
declares 50K bytes of local data. The
compiler should generate a LINK
instruction for the first 32K bytes and
then adjust the stack for the remaining
18K bytes needed by the routine. If the
program is compiled specifically for the
68020 or 68030, the compiler can issue a
LINKL (link long) instruction, which
allows a full 32-bit offset.
—Chuck Lins
Thanks for the clarification. You’re
absolutely right, but of course for most of us
it doesn’t make any difference; we don’t
write our compilers, we’re slaves to them. I
guess the answer should have read “is
basically due to the way that current
compilers handle local data.” All you
aspiring compiler writers, take note.
—Dave Johnson
• After receiving   Gorillas in the Disc
(Developer CD Series   Volume VI) a few
months ago, I checked out the electronic
versions of the   develop   issues that we did
not have in hardcopy, and came across
something that prompted me to write. I
was reading the letters in   develop   Issue 2
(April 1990) and saw a letter and
response in which you mentioned the
“ever-popular audio track” from the
develop   CD. Because we are an Apple
Partner, our copy of   develop   contains a
card telling us that Developer Essentials
will be included in a folder on our
Developer CD Series   disc. Imagine my
disappointment when I realized that the
disc Apple Partners received contained
no audio track. What a crime to deprive
all us Partners of such a bonus! Please
tell your people that Partners want their
audio!
—Bill Stoker
The Developer CD Series disc contains a
superset of what’s on the disc that’s bound
into   develop   (now called the Developer
Essentials disc). Volume III of the Developer
CD Series (“A Disc Called Wanda”)
corresponds to   develop   Issue 2 and does
indeed contain the ever-popular audio track,
as part of the CD Audio Toolkit demo. Were
you looking for an audio track on the latest
Developer CD Series disc? If so, you would
in fact not find one there; there wasn’t one
on the corresponding Developer Essentials
disc, either. Rest assured that we won’t
deprive Apple Partners of any of the goodies
we provide on the Developer Essentials disc!
—Caroline Rose
• First let me say that   develop   is great!
I read on page 5 of the latest issue that
your group is now responsible for the
Developer CD Series .   Gorillas in the Disc   is
a bit of a disappointment. Not a lot of
really new stuff on it. That’s not your
fault, I know. There must be neat stuff
floating around in Apple somewhere!
Someone decided that the Q & A Stack
should contain both Macintosh and
Apple IIGS stuff. Boo, hiss! I tend to read
through that stack looking for stuff I
d e v e l o p   Spring 1991
COMMENTS
We welcome timely letters to the editors,
especially from readers reacting to articles that
we publish in
develop. Letters should be
addressed to Caroline Rose (or, if technical, to
Dave Johnson) at Apple Computer, Inc., 20525
Mariani Avenue, M/S 75-2B, Cupertino, CA
95014 (AppleLink: CRose or Johnson.DK).
All letters should include name and company
name as well as address and phone number.
Letters may be excerpted or edited for clarity
(or to make them look like they say what we
wish they did). •
4
LETTERS

Reading notes: Source text contains line-break hyphenation and page-layout artifacts (e.g., 'd e v e l o p' spacing) that may affect reading order.

Printed product names: Macintosh · develop · Gorillas in the Disc · Developer CD Series · Developer Essentials · Apple IIGS · CD Audio Toolkit · A Disc Called Wanda

Printed dates: Spring 1991 · April 1990

Languages: English

[Original PDF page 6](https://www.vintageapple.net/files/55be35a2a9d841c7e1b82c2183e0dcecd3715cf688a1caceff9e91afe507c3cc/develop-06_9104_Spring_1991.pdf#page=6)

### PDF page 7

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-06-9104-spring-1991-8d7fb4/1#scan-d94d76948d87ae3576fe5a407b5505573da43c373ee1b3e451b259f3312adbf0)

Transcribed text:

LETTERS   Spring 1991
5
don’t know, before I know I need to
know it! I was really confused by things
that I had never heard of on the
Macintosh before, only to find they were
on the Apple IIGS! Arrggh! Can you
please separate the IIGS stuff and the
Macintosh stuff into two stacks? And can
you please go back to the format of
putting dots beside the new stuff?
The X Ref stuff is kinda neat. Can’t wait
for 7.0 aliasing!
—Scott Anguish
Thanks a lot for your letter and your words
of encouragement. My group contributes to
the Developer CD Series, but we’re not
actually responsible for it. Besides adding
more new “neat” stuff, is there anything we
could do to improve the disc? We’re always
looking for suggestions!
Sorry to hear that adding Apple IIGS stuff
to the Q & A stack confused you so much
(but I’m awfully glad to hear that you’re
browsing the Q & A stack!). We put the
IIGS info in the stack hoping that Macintosh
developers would see how similar the two
toolboxes are and perhaps get some extra
mileage from their work by porting their
Macintosh application to the IIGS. It sounds
like it’s more confusing than helpful, so we’ll
reevaluate our decision. What do the rest of
you think about combining IIGS and
Macintosh information in one stack?
In reply to your request for dots: The latest
Q & A Stack has been reworked so much it’s
practically all new, but in the future you can
expect to once again see dots beside new
material. Also note that, starting with the
latest stack, each card will show the date of
the last modification.
—Louella Pizzuti
• Just a quick note to congratulate you
and your staff on another fine issue of
develop   (and in the hopes that I won’t see
a survey). I read it cover to cover, and
thoroughly enjoyed it, especially the
Macintosh Q & A. I kept turning the
page expecting to have seen the last
question answered, but lo and behold,
there were more questions. It was better
than Jeopardy. You really outdid
yourselves! Keep up the wonderful
work, and please consider starting a new
column: a soap opera about the dogcow.
By the way, whose nose is lighting up
the cover?
—Robert H. Zakon
Thanks for the letter. If we ever do a survey
(and my boss has been pushing me to do one
ever since Issue 2 came out), I’ll make sure
that the surveyors know you’re officially
exempt.
The nose on the cover belongs to Cleo
Huggins, who has done all our covers and
nose what she’s doing.
—Louella Pizzuti

Reading notes: Some running text is hyphenated or interrupted by page markers, and the reading order of the letters between pages is somewhat uncertain. Heading 'develop' appears with irregular spacing and may be a masthead rather than a product name.

Printed product names: Macintosh · Apple IIGS · Developer CD Series · Q & A · X Ref · develop

Printed dates: Spring 1991

Languages: English

[Original PDF page 7](https://www.vintageapple.net/files/55be35a2a9d841c7e1b82c2183e0dcecd3715cf688a1caceff9e91afe507c3cc/develop-06_9104_Spring_1991.pdf#page=7)

### PDF page 8

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-06-9104-spring-1991-8d7fb4/1#scan-66e314618271112ecfad162a5be0d166264a4432bbc5fd429a47941287009527)

THREADS ON THE MACINTOSH

Transcribed text:

Threads are a great way to improve the performance and simplify the
design of programs. Apple’s Advanced Technology Group developed a
Threads Package to implement this programming technique on the
Macintosh. This article explains how you can use this package to
incorporate threads in your own code.
The idea for the Threads Package arose during the design phase of some scientific
visualization software, when we discovered that some of the applications we were
working on needed a way to juggle several simultaneous activities. It quickly became
clear that the Macintosh run-time environment posed some serious obstacles to
anyone wanting to implement threads on the Macintosh. With some effort, we were
able to come up with workarounds that made the use of threads with the Macintosh
OS relatively painless.
These workarounds are the main subject of this article. After briefly introducing the
purpose and mechanics of threads in general, the article presents some specific
details of the Macintosh threads implementation as it currently stands. A summary
of the functions in the Threads Package appears at the end of the article. The
Threads Package itself and several simple example programs can be found on the
Developer Essentials   disc for this issue.
The Threads Package was developed as a means to an end, and it’s by no means the
last word on threads for the Macintosh. We welcome any suggestions you may have
for improvements.
WHAT THREADS DO
Suppose you want to write an AppleLink ® -like communications program. You’d like
to write the program so that while it’s downloading a file, it can also print an existing
file and allow the user to write a new message. A typical program can perform only
one of these functions at a time, displaying the watch cursor until the task is
completed. What’s needed is some technique for allowing the program to perform
these tasks concurrently.
6
MICHAEL GOUGH
THREADS
ON THE
MACINTOSH
d e v e l o p   Spring 1991
MICHAEL GOUGH   is a designer in Apple’s
User Programming Group. We’d tell you what
he’s up to these days, but it’s so secret we’d have
to kill you if we did. Before coming to Apple,
Michael worked at STX as a NASA contractor,
designing scientific data visualization systems. He
is best known as the designer and implementor of
CDF, a “mini-database” that NASA uses to store
data from dozens of spacecraft. Michael
developed software used by NOAA’s fleet of
oceanographic vessels to map the ocean floor.
He also worked as a contractor to the United
Nations World Meteorological Organization, so
if you have any problems with the weather, now
you know who to blame. While he was there, he
developed real-time satellite tracking and data
ingest systems for the TIROS-N, GOES, and GMS
spacecraft, and conducted training and
6

Reading notes: Source text contains line-break hyphenation and a possible page-number artifact '6'.

Printed product names: AppleLink · Macintosh · Developer Essentials · CDF · TIROS-N · GOES · GMS

Printed dates: Spring 1991

Languages: English

[Original PDF page 8](https://www.vintageapple.net/files/55be35a2a9d841c7e1b82c2183e0dcecd3715cf688a1caceff9e91afe507c3cc/develop-06_9104_Spring_1991.pdf#page=8)

### PDF page 9

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-06-9104-spring-1991-8d7fb4/1#scan-57799724520ed054393561ea2421402d1df18157b130b7591edf08804d93312c)

Transcribed text:

Programmers have often tried to achieve concurrency through the use of idle procs.
For your communications program, for instance, you could write the downloading,
printing, and text entry tasks as idle procs. While the download procedure is
executing, it could regularly call a printing idle proc to send a few lines of a message
to the printer. The download procedure could also periodically call an editing
procedure to allow the user to enter text for a new message in a window.
But think of the tremendous effort involved in writing the program so that it can
switch among these tasks. Every task would have to save variables each time it
returns so that it could resume where it left off. Most complex functions would not
be able to contain deep levels of nesting because that would make it impossible to
freely return to the caller at any time. In fact, you’d have to divide most functions
into inconveniently small chunks so that you could juggle between them. The net
result is that the modularity of your program would be destroyed, and you’d have a
tremendous programming headache on your hands.
Threads are a much better technique for achieving concurrency than idle procs.
When your program uses threads, it’s like a mind that can have several trains of
thought simultaneously. A program using idle procs, in contrast, is like a mind with a
single train of thought that must constantly interrupt itself to attend to side issues.
Note that there’s a difference between multithreaded programs and multitasking
systems. Multitasking is the ability to run more than one application at once, but each
THREADS ON THE MACINTOSH   Spring 1991
7 installation in Beijing and Buenos Aires. In Beijing
he used his knowledge of electronics, computer
science, math, and Scotch tape to successfully
complete the installation—just goes to show that
you never quite know what the right tools for the
job are going to be. (Here at Apple, we make
sure he always has plenty of office supplies—just
in case.)   •
WHY THREADS ARE IMPORTANT IN THE SYSTEM 7.0 ERA
Interprocess communication (IPC) is one of the most
compelling reasons why threads are going to become
increasingly important in the future. This became clear to
a group of us working in Apple’s Advanced Technology
Group when we observed that a client and a server
application communicating via IPC could easily get into a
deadly embrace. A client would ask the server
application a question and would wait for an answer
before continuing. Unfortunately, sometimes the client
would wait forever for the answer. What happened was
that the server needed to ask its own question of the client
before answering the client. However, the client was
monitoring exclusively for a response to its question and
would ignore the server’s question. The client needed to
answer the server’s incoming question before it could get
an answer to its own question. Both client and server
would be stopped dead waiting for the other to respond.
In a sense, the Threads Package exists because the
problem described here was intractable without threads.
The application must be both a client and a server. It must
be able to simultaneously handle incoming questions and
wait for incoming answers. Other approaches to doing
this, such as idle procs, skirted the core of the problem
and led to code complexity that was unmanageable. Idle
procs push too much of the problem onto the application
programmer, who already has enough to worry about.
The threads solution is even more important now that IPC
has been integrated into the Macintosh OS in System 7.0.
As more programmers will have access to IPC because of
System 7.0, they will need this elegant method of
achieving concurrency.

Reading notes: Page header and footer text ('THREADS ON THE MACINTOSH Spring 1991', '7') is mixed into the body copy, so reading order across the two columns is uncertain.

Printed product names: System 7.0 · Macintosh OS

Printed dates: 1991 · 7.0

Languages: English

[Original PDF page 9](https://www.vintageapple.net/files/55be35a2a9d841c7e1b82c2183e0dcecd3715cf688a1caceff9e91afe507c3cc/develop-06_9104_Spring_1991.pdf#page=9)

### PDF page 10

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-06-9104-spring-1991-8d7fb4/1#scan-b9a5cc946ae3bec8e3f958bf0002e2384b72c6c400deae3d941a76ff2eb725ae)

Transcribed text:

application can still only do one thing at a time. In other words, concurrency is
happening at the system level. A multithreaded application performs concurrent tasks
within the same program; concurrency happens at the program level. Of course, it’s
possible to have a multitasking environment in which threaded programs run.
d e v e l o p   Spring 1991
8
HOW THREADS WORK
When writing multithreaded code, you must let go of old ideas about how the
machine executes your program. Instead of a single program counter marching
through your code, in a sense you now have many. While the idea of multiple
program counters may sound complex, you don’t have to relearn programming. You
just need to be aware that the main train of execution in a program is itself a thread
and that all threads must relinquish control to each other. You also have to
remember to share globals and heap objects that you used to access exclusively.
Here’s a sample program that shows how simple it is to use threads. The program is
a modified version of the ever-popular SillyBalls. Unmodified, the program opens a
window and draws colored balls into it until the main event loop detects that the
mouse button is down. This new version forks a thread that beeps while the balls are
being drawn.
IDLE PROCS VERSUS THREADS
Idle procs have traditionally been used to approach
thread-like functionality. This involves writing a piece of
code to handle a particular task and installing it in a
queue of things that get called periodically. Thereafter, the
flow of control pulses through the routine, which can do
some finite amount of work and then return, so that other
idle procs can get pulsed.
This approach results in several gnarly coding problems.
The most serious is that the pulsed routine, which is
attempting to execute some algorithm, must return to its
caller at inopportune moments. Imagine that you’re
marching through a deeply nested piece of code and you
want to relinquish control when you reach a certain point.
With the pulsing approach, you must return to the caller
from deep within the nested code. You could put in a
return statement, but the problem would be that when it’s
time to pick up where you left off, you would have to
magically jump back into the code after the return
statement on the next pulse. Obviously, this is not a simple
thing to do when you have to bypass several layers of
conditionals and loops.
The magic of the Threads Package is that it allows you to
avoid these problems: you can leave a complex function
and resume execution of it precisely where you left off.
With idle procs, on the other hand, you’re forced to
completely redesign the algorithm. You must give the
algorithm an “inside out” appearance: code that was in
the most deeply nested part of the algorithm now appears
near either the top or the bottom of the routine. You may
even have to break your routine into several smaller
functions that are run in sequence. But doing these things
will negate the natural top-down structure of a routine. It’s
a mess.

Reading notes: Running headers and sidebar boundary between main text and 'IDLE PROCS VERSUS THREADS' box may affect reading order. Letter-spacing in 'd e v e l o p' header line is irregular.

Printed product names: SillyBalls · Threads Package

Printed dates: Spring 1991

Languages: English

[Original PDF page 10](https://www.vintageapple.net/files/55be35a2a9d841c7e1b82c2183e0dcecd3715cf688a1caceff9e91afe507c3cc/develop-06_9104_Spring_1991.pdf#page=10)

### PDF page 11

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-develop-06-9104-spring-1991-8d7fb4/1#scan-8fa2d5750b75665cd6b3e86d440e7db8920743a3e7739643eeadcef2bba3585d)

Transcribed text:

main()
{
ThreadHandle   beepThread;
Initialize();
/*   The   InitThreads   call   initializes   the   Threads   Package,   converting
the   original   thread   of   execution   into   a   swappable   thread.   */
InitThreads(nil,   false);
/*   This   code   forks   a   thread   that   beeps   30   times,   and   then   quits.   */
if   (InNewThread(&beepThread,   kDefaultStackSize))
{
long   i;
for   (i=0;   i<30;   i++)
{
SysBeep(120);
Yield();
}
EndThread(beepThread);
}
/*   Here's   the   main   event   loop.   The   only   change   is   the   new   call   to
Yield.   */
do
{
Yield();
NewBall();
}   while   (!Button());
/*   This   call   to   ExitThreads   waits   for   all   threads   to   die   before
allowing   the   program   to   terminate.   */
ExitThreads();
}
The InitThreads call is made at the beginning of the program. It initializes threads
and converts the original thread into something that can be swapped by the Threads
Package. Once this call is made, you can fork other threads.
THREADS ON THE MACINTOSH   Spring 1991
9

Reading notes: Source text contains C-style code with extraction spacing artifacts around punctuation and operators.

Printed dates: 1991

Languages: English

[Original PDF page 11](https://www.vintageapple.net/files/55be35a2a9d841c7e1b82c2183e0dcecd3715cf688a1caceff9e91afe507c3cc/develop-06_9104_Spring_1991.pdf#page=11)

[Next transcribed scans](https://www.vintageapple.net/transcripts/media/va-develop-06-9104-spring-1991-8d7fb4/2.md)
