In February 1978, four teams handed the US Department of Defense their preliminary designs for the language that, a year later, would be named Ada. The designs were anonymized, and instead of company names they carried colours. Green came from Jean Ichbiah’s French-American team, Red from Intermetrics in Boston, Blue from SofTech, and Yellow from SRI International, a research institute in California. That spring, Green and Red went through to the second round, Blue and Yellow went into the archive, and a year after that Green won and became Ada.

How Ada was chosen

How Ada was chosen: four designs in February 1978, two in the second round, one winner in May 1979

In the article about the finalists, I rebuilt Red and Green from their 1979 documents. I wrote a compiler for each one in the language itself, and then built an operating system and Kubernetes on top of both. At the time, Blue and Yellow looked out of reach. Their descriptions sat in a 4,500-page volume that the Defense Department’s archive had just stopped serving. Then a copy turned up in a web archive, and I did the same thing with these two languages.

This post is about the two designs that lost to Green and Red. Blue is built around types so consistently that even assignment is defined as an operation of a type. Yellow is Pascal reworked to meet the military’s requirements. Its tasks don’t talk through rendezvous, the way they do in Green and in Ada, where one task waits for another at an agreed entry until the two meet. Instead they talk through Hoare’s monitors: modules with shared data that only one process can be inside at any moment. For both languages I wrote compilers in the languages themselves, and those compilers ran, for the first time ever, programs that the language designers printed in their 1978 reports and that nobody had seen working since. On top of that, both languages now run THE, the multitasking operating system that Dijkstra’s group built in the 1960s, and Kubernetes on top of it.

But the most interesting part isn’t the languages themselves. It’s that all four designs can now be put side by side and compared by running code rather than by reviews. The same example behaves differently in each of the four, and the differences turned out to be far more interesting than I expected. In the 1978 blue language, when one of several parallel branches fails with an error, whoever started those branches finds out about it, something mainstream languages only learned to do in the last few years. Its mutex is released automatically if the branch holding it ends abnormally. And the yellow language has artificial time built in: the clock moves only when the program wants it to.

It’s a long post, so here’s the map. First I’ll tell you about the 1978 book these texts come from and about the people who designed the languages, and then we’ll walk through Blue and Yellow one at a time. After that we’ll run the same examples in all four languages and collect the differences in a table, look at the compilers and the 1978 programs, at THE and Kubernetes, and try to understand why these designs lost. At the end I’ll look at what Ada later inherited from them and at what the industry might have looked like if Blue or Yellow had won.

This is the latest part of my series on paleocomputing. I’m curious about the ideas that lived in technologies that never took off or stayed the province of enthusiasts and theorists, about what we lost along with them, and about which of those lost ideas later came back in other technologies. You don’t need to read the article about the finalists first: wherever it matters, I’ll briefly recap how Red and Green work.

All the sources, notes and instructions are in the github.com/tym83/paleocomputing repository, in the impl/ada-colors directory, under the Apache 2.0 license.

A book made for microfiche

Let’s start with where the texts came from. In 2023, an interesting message appeared on the systemsafety mailing list, where people discuss the reliability of software for critical systems. At the request of one enthusiast, DTIC, the Defense Department’s archive of technical documentation, had scanned a 4,575-page volume called “DoD Common High Order Language, Phase 1”. It’s listed in the archive’s catalogue as ADB950587, and it contains all four designs from the first round. While I was busy with Red and Green, the DTIC site first went down for maintenance and then started refusing every request. The Wayback Machine came to the rescue: in September 2023, someone had saved the whole PDF there. The volume carries the same marking as the Red manual: “approved for public release, distribution unlimited”.

The preface of volume ADB950587

The preface of volume ADB950587

The colour key on the next page

The colour key on the next page: Green is CII-Honeywell Bull, Red is Intermetrics, Yellow is SRI International, Blue is SofTech

The book’s preface is a historical document in its own right. The compilers explain that the book was made for microfiche, sheets of film with shrunken pages that you read through a magnifier, and that there was never a bound version: all two hundred printed copies went straight to the reviewers, so the microfiche set is the only one that can be distributed at all. The preface also reveals all the colours and who was behind each one. And it ends with a sentence I read several times over. The losing designs will not be continued, they are of interest perhaps only to researchers, the goal of the program is to arrive at a single language, and the Department of Defense considers it inappropriate to encourage alternatives.

Inside are the four designs exactly as they were submitted on February 15, 1978. Red appears in its first edition: this is the REDL with monitors that the red team later threw out and essentially rewrote from scratch. After the designs come the analyses sent in by eighty teams, from universities to defense contractors, and the report of the Pittsburgh panel. The panel members studied those analyses, questioned the language designers and boiled everything down to the tables that were used in April 1978 to decide who would make the final.

The OCR text is awful in places: a zero instead of the letter O, a dollar sign instead of S, the letter l instead of a percent sign. So I checked every program against the page image, and the blue programs, full of backslashes and hash signs, I simply retyped from the pictures.

Who made the blue and yellow languages

The blue design was led by John Goodenough of SofTech, and his name is far from a footnote in Ada’s history. In 1975 he published one of the first major papers on exception handling in Communications of the ACM, and after the competition SofTech, under his leadership, won the contract for the test suite used to check Ada compilers against the standard. Goodenough later headed the group that interpreted the standard and wrote requirements for Ada 95. So although the blue team lost, it went on working on Ada for another two decades.

The yellow design was led by Jay Spitzen of SRI International, where in those years people were building SIFT, a fault-tolerant flight computer for aircraft. We’ll come back to it. A popular Time-Life book from 1986 and Bertrand Meyer both say that Hoare and Wirth consulted for the yellow team. The document itself doesn’t name its consultants, but their ideas are on every page. The language description is structured like Wirth’s description of Pascal, the modules come from his Modula, the monitors from Hoare’s 1974 paper, and the bibliography includes the entries “Hoare, private communication” and “Wirth, private communication”.

What Dijkstra thought of them

Dijkstra spent all of March 1978 reading the four designs and wrote a review of each one. Blue got it for its chapter on types and operations, which, in his words, had “grown to 160 (!) pages”. He called Yellow a hopeless mess and added that he felt sorry for the consultants who had failed to prevent it. Once you remember who the yellow team’s consultants are said to have been, that line lands with real bite.

He wasn’t thrilled with Red and Green either, so going by his reviews you couldn’t tell the losing designs from the winning ones. In the end the decision came down to the reviewers and the panel of experts, and I’ll return to their conclusions once I’ve shown both languages at work.

BLUE: a language in which everything rests on types

Of the four languages, Blue is the least familiar, so I’ll start with a short program from a lab. In it, one and the same procedure swaps two integers, two strings and two colours:

TYPE COLOR = ENUM (\RED, \GREEN, \BLUE); VAR I, J: INTEGER; VAR A, B: ASCII_STR (4); VAR K, M: COLOR; ... SWAP (# I, J); SWAP (# A, B); SWAP (# K, M); PROCEDURE SWAP (# X, Y: ?T) WHERE T NEEDS (STORE_ (T ## T)); VAR TMP: T; TMP := X; X := Y; Y := TMP; END PROCEDURE SWAP; FUNCTION FRAME (S: ASCII_STR (?L)) RETURNS (ASCII_STR (L + 2)); RETURN '[' !! S !! ']'; END FUNCTION FRAME; 

Almost every symbol here means something, so let’s take them one at a time.

This is how the blue language looked in the specification itself

This is how the blue language looked in the specification itself: a generic stack where ?T infers the element type, # separates the groups of parameters, SIGNALS lists the exceptions, and WHERE T NEEDS says what is required of the type

Enumeration literals are written with a backslash: \RED, \GREEN. That’s not a whim. A literal in Blue doesn’t belong to any single type, so \GREEN can be both a traffic-light colour and a rainbow colour at once, sitting at its own position in each of those types. Context decides which one is meant, and when there isn’t enough context, you name the type explicitly: [COLOR]$$(\GREEN). There are also unordered enumerations, UNORDERED, which define nothing but equality. A card suit is never greater or less than another suit, and the language won’t let you pretend otherwise.

A procedure’s parameters fall into three groups, inputs, updated parameters and outputs, and hash signs separate the groups. In SWAP (# X, Y) there are no inputs, and both parameters are updated. In STORE_ (T ## T) there’s one input of type T, no updated parameters, and one output of the same type: assignment takes a value and produces the variable’s new value. The groups are visible at the call site too, so SWAP (# I, J) tells the reader right away that I and J will change.

?T is a generic type inferred from the argument. An instance of the procedure for each type is created automatically, right at the call, and nobody has to name or declare it. Red worked the same way, while in Green and in Ada you have to create the instance explicitly. And it’s not just types that can be inferred. ASCII_STR (?L) takes the string’s length from the argument, and the FRAME function promises to return a string of length L + 2, because length is part of the type here and the compiler knows it.

Finally, WHERE T NEEDS (STORE_ (T ## T)) is the list of what the procedure body needs from type T, and here all it needs is assignment. These operations are taken from wherever the procedure was called. If the type has no assignment, the call won’t compile, and the compiler reports a clear error right at the call site instead of somewhere deep inside the instance. Today we call this concepts in C++ and trait bounds in Rust.

Assignment is a function too

STORE_ in the previous example isn’t a typo. In Blue, every operation, whether it’s assignment, comparison or taking a substring, is a call to a function with a fixed name: ADD_, EQUAL_, LESS_THAN_, SUBSTRING_, STORE_. That means an abstract type exported from a module defines its own addition and its own assignment the same way, as ordinary subprograms. Ada still has no user-defined assignment: Ada 95’s controlled types let you say what happens after a copy and before destruction, but not the assignment itself. C with Classes, the predecessor of C++, already let you redefine assignment in 1980.

One of the 1978 reviewers wrote that Blue came closest of all to making the type the thing that holds the whole language together, and you can see it in every detail.

Take numbers. Computers of the 1970s often had no floating point, so fractional quantities were stored as integers with an implied decimal point, for example speed in hundredths of a metre per second. That’s fixed point, and usually the programmer had to remember where the point sat in each variable. In Blue, the type remembers. FIXED (scale, radix, precision) says how many places the point is shifted, in which radix and with what precision, and the compiler lines the points up itself when it adds or compares such numbers. Even INTEGER here is just fixed point with the point at the very end. No other design describes fixed point in such detail.

Strings work the same way. The character set is part of a string’s type: in CHAR_STR (L, C), L is the length and C is the character set, ASCII or, say, one of the many six-bit BCD codes that machines of the day used. So you can write one function for strings in any encoding, and the compiler won’t let you concatenate an ASCII string with a BCD one.

Even talking to hardware rests on types. The codes a device uses to report its state were chosen not by the programmer but by the engineer who designed the board. In Blue such a state is described with an ordinary enumeration, and each value is assigned the code the hardware picked:

TYPE STATUS = UNORDERED (\IDLE, \BUSY, \DONE, \FAULT) REP ENUM_VAL_REP (4, VALUES (\IDLE AS BIN '0000', \BUSY AS BIN '0001', \DONE AS BIN '1000', \FAULT AS BIN '1111')); ... SELECT OBJECT_MACHINE FROM PDP_11 --> S := [STATUS]$$(REGISTER); END; END SELECT; 

Two details are worth noticing here. Only an unordered type may be given its own codes, because hardware codes can come in any order, and then you can no longer tell from them which value is greater. Ada arrived at the same place from the other side: it lets you assign codes to any enumeration, but they must be increasing. And reading a code from a device register as a value of the type is allowed only in the machine-dependent part of the program, inside SELECT OBJECT_MACHINE, where the program says outright which hardware it’s doing this on.

Closed scopes and declared exceptions

As in Red, a procedure in Blue is a closed scope: it can’t see outside variables until it imports them. But Blue is stricter than Red here. A procedure that calls another procedure must import either that procedure or every variable it touches, so the header of any procedure shows which data it can reach through the whole chain of calls. The hash sign in an import list works the same way as in parameters. In IMPORTS (DATA: (# MUTEX, BALANCE)) everything comes after the hash, meaning both variables are imported for updating, while anything the procedure only reads goes before it. A blue program itself consists of segments, units of translation that list in a USES clause what they take from one another.

Exceptions in Blue are declared in the subprogram header, for example SIGNALS (OVERFLOW, INVALID_FORMAT), and a subprogram can’t let an exception escape unless it’s on that list. SofTech’s rationale justifies this the same way it justifies import lists: a procedure’s interface should be described completely, and what it can raise is as much a part of it as what it can change. In 1978 hardly anyone did this outside Barbara Liskov’s CLU, and checked exceptions, the kind the compiler makes you declare or handle, reached mainstream languages only with Java. Ada has never had them.

An exception handler in Blue is attached to a statement, not to a block, and EXCEPT can follow any statement. That sounds like a detail until you write BLOCK ... EXCEPT ... END BLOCK and discover that the handler covers only the last statement of the block, not the whole block. I fell for it, and it’s now a separate entry in the compiler notes.

The parallel block

When it comes to concurrency, Blue is the strictest of the four. It has no tasks in the usual sense. Instead there’s a parallel block, PAR_BLOCK, with parallel paths, PATH, inside it, and the block doesn’t end until all of its paths have ended. The block itself isn’t new; it’s Dijkstra’s parbegin ... parend from 1965. What’s new is this: if a path raises an exception it doesn’t handle but is allowed to raise, the block waits for the remaining paths and then raises that exception itself, so a failure in a path becomes a failure of the block that can be handled outside it.

Here’s an example. The block has two identical paths, WORKER 1 and WORKER 2, and each adds 10 to a shared balance that starts at 100. To keep the paths from getting in each other’s way, the balance is guarded by the MUTEX semaphore: a path acquires it with REQUEST, changes the balance and lets go with RELEASE. I’ll come back to semaphores in a moment. The first path deliberately fails with FAILED while it’s holding the semaphore. For now, keep an eye on SIGNALS (FAILED) in the path header and on the EXCEPT after the block:

VAR MUTEX: SEMAPHORE (REGION) := NEW (1); VAR BALANCE: INTEGER := 100; PAR_BLOCK PATH WORKER FOR ID IN [1:2] SIGNALS (FAILED) IMPORTS (DATA: (# MUTEX, BALANCE)); PAUSE (ID); % PAUSE and LOG are my procedures: a wait in milliseconds REQUEST (# MUTEX); % and a timestamped log line PAUSE (5); IF ID = 1 THEN SIGNAL FAILED; END IF; BALANCE := BALANCE + 10; RELEASE (# MUTEX); END PATH WORKER; END PAR_BLOCK; EXCEPT FAILED --> LOG ('the block signals FAILED: worker 1 ended abnormally'); END; END EXCEPT; 

The same example in the browser

The same example in the browser: the first path fails holding the semaphore, the second gets it right away, and the block raises FAILED. The output is slowed down; on the virtual clock the program finishes in a fraction of a second.

Today this approach is called structured concurrency. Parallel branches are nested in the program’s block just like ordinary statements: the block doesn’t end until they do, and if one of them fails, whoever started the block finds out. About eight years ago this idea started showing up again everywhere: in the Trio library for Python, in Swift’s task groups, in Java’s StructuredTaskScope. Blue is simpler. If one path fails, its siblings keep running, and you have to stop them yourself with TERMINATE; if two paths fail, only one of the two exceptions makes it out. And TERMINATE doesn’t cut a path off mid-sentence. The path receives a TERMINATED exception the next time it gets its turn to run, and it can catch it, for instance to clean up after itself. Paths also have priorities: when two of them are ready to run, the processor goes to the one with the higher priority.

In Ada 83, a block also waits for its tasks, but if an exception in a task goes unhandled, the task simply terminates. The exception isn’t passed on anywhere, and whoever started the task never learns that it failed. It’s one of Ada’s best-known traps, and the 1978 blue language doesn’t have it.

That strictness has its price. A parallel block can’t be placed inside a subprogram, so you can’t start a couple of paths from a procedure, and that will come back to bite us in the blue Kubernetes.

Two kinds of semaphores

Blue has neither mailboxes, the message queues between tasks that Red has, nor Green’s rendezvous. Paths coordinate through semaphores. Dijkstra’s semaphore is a counter with two operations: P waits until the counter is greater than zero and decrements it, and V increments the counter and wakes one of the waiters. In Blue, semaphores come in two kinds, and the difference between them is subtle. SYNCH is a classic semaphore with no owner: one path waits for an event, another announces that it happened. REGION is a lock around shared data, and it does have an owner; today we’d call it a mutex. If the path holding such a lock ends abnormally, the lock releases itself.

Section 3.11 of the SofTech specification

Section 3.11 of the SofTech specification: SYNCH and REGION semaphores. REGION semaphores that a path has acquired and not released are released automatically when it ends abnormally

Back to the example above. The first path fails without ever releasing the semaphore, but it’s a REGION semaphore, so the system releases it on its own. The second path gets it immediately and adds its 10, and the program runs to the end with a balance of 110 instead of hanging forever on a semaphore that no one is left to release. Importantly, the system releases the lock only if the path died, that is, if nobody caught the exception. If the path caught the exception itself and kept going, its locks stay with it. One of the labs is built around this.

So why not release every semaphore when a path dies? SofTech’s rationale has an answer for that too. The fact that a path holds a lock can be recorded only inside the acquire operation itself. If you record it with a separate instruction right after acquiring, the path can die in between, when the lock is already taken but the note saying who took it hasn’t been written yet. So it has to be the system that releases a dead path’s lock, not an exception handler in the program. But if the system released every semaphore indiscriminately, it would release the signalling ones as well, and whoever was waiting on them would receive signals about events that never happened. That’s why there are two kinds, and only locks release themselves.

This design has an obvious weakness, and SofTech doesn’t hide it. A path may die halfway through a write, and then the next path gets the lock together with half-updated data. SofTech accepted that, reasoning that for the computers inside aircraft, ships and missiles, the very machines the language was meant for, it’s not a disaster: their data usually comes from sensors and will be overwritten with fresh readings a moment later. About thirty years later the authors of POSIX, the standard that Unix systems are built around, faced the same problem and decided to warn the next owner. When the owner of a so-called robust mutex dies, whoever acquires the mutex next gets the EOWNERDEAD code, which means the previous owner died and the data may be corrupted. The new owner has to check the data and declare it consistent, or the mutex becomes unusable. Blue has no such warning, and the lock passes to the next owner in silence.

Time in Blue is also a little unusual. WAIT (30) puts a path to sleep for thirty seconds, but seconds here are stored as a binary fixed-point fraction, so you can’t write exactly one millisecond, just as you can’t write exactly one third as a decimal fraction. And CLOCK, as far as I can tell from the specification, shows not the time of day but how long the path itself has been running. That’s why my programs take log timestamps from the simulated machine’s clock.

YELLOW: Pascal told to satisfy Ironman

If Blue started from types, Yellow started from Pascal. The Department of Defense wrote its language requirements in stages, and the editions were called Strawman, Woodenman, Tinman, Ironman and Steelman, from a man of straw to a man of steel, each more detailed than the last. The first-round designs were based on the 1977 Ironman, and SRI says plainly in its report that its goal was to design a language by reworking Pascal to meet those requirements. The yellow language description is divided into sections numbered exactly like Wirth’s description of Pascal, and one section is even left empty just so the numbers line up. A program in it reads like Pascal with long closing keywords:

MODULE Enumerations IMPORT TextIO, StandardImplementationPrelude; REPRESENTATION Phase = ORDERED (Pending, Running, Succeeded); Fruit = UNORDERED (Lemon, Lime, Orange); VAR p: Phase := Pending; PROCEDURE WritePhase (CONST p: Phase) SELECT p CASE Pending => Write("Pending") CASE Running => Write("Running") CASE Succeeded => Write("Succeeded") ENDSELECT; RETURN ENDPROCEDURE WritePhase; FOR q: Phase DO WritePhase(q); Write(" ") ENDFOR; ... ENDMODULE Enumerations 

To Pascal, SRI added modules from Modula, monitors and signals, module templates, exceptions and overloading. Case matters: reserved words are written in capitals, and names however you like. ASCII had no “not equal” sign, so, as in Modula, it’s written with a hash.

Type and representation

The main thing SRI invented itself is the split between type and representation. A representation here isn’t a memory layout, like REP in Blue, but a constraint on values. INTEGER is a type, a set of values together with the operations on them, and INTEGER [1..10] is one of its representations, the integers from one to ten. For floating-point numbers a representation also sets the precision, and for fixed-point numbers the step. A variable can be declared only with a representation; plain INTEGER isn’t enough. In return, different representations of the same type are compatible: INTEGER [1..5] and INTEGER [0..9] are still the same type, and assignment only checks that the value falls in range. Enumerations are also declared as representations, in a REPRESENTATION section, as in the example above.

Chapter VI of the yellow specification

Chapter VI of the yellow specification: a type is a set of values, a representation is a subset of it or a way to store it. The type INTEGER and the representation INT

In Ada, the same thing is called a subtype: subtype SMALL is INTEGER range 1 .. 10 doesn’t create a new type, it just narrows the old one. The difference is that in Ada a subtype is an optional extra, whereas in Yellow you can’t do without a representation. To create a genuinely new type you need a separate declaration, TYPE T = INTEGER, and numbers of that type are written together with its name: T 50.

Enumerations can be ordered or unordered, as in Blue, and BOOLEAN here is unordered: true isn’t greater than false. Names can be overloaded only explicitly. If a new function has the same name as an existing one, you mark it EXTENDS when it adds to the old ones or REPLACES when it replaces them, and without a mark the new declaration hides all the old ones. So you can’t overload anything in Yellow by accident, and a reader can see at once where a name has taken on a new meaning.

Two rules you trip over on day one

You can’t chain subtraction in Yellow. Addition and multiplication are associative, so a + b + c needs no parentheses, but a - b - c is a syntax error, and so is a * b DIV c; you have to spell out the order with parentheses: (a - b) - c. Pascal and nearly every other language simply read such an expression left to right. This wasn’t SRI’s whim. Ironman demanded it: under requirement 4G, parentheses are mandatory when operators of the same precedence follow one another and the left one is non-associative. SRI met the requirement to the letter, while SofTech wrote plainly in Blue’s rationale that the requirement should be dropped, and in the next edition it was softened to a recommendation.

The second rule is sneakier, and it comes from Pascal. In Yellow, as in Pascal, comparisons have the lowest precedence, lower than AND and OR. So x > 0 AND b is read as x > (0 AND b) and doesn’t compile. It’s worse when the types happen to match: then there’s no error at all, and for Boolean f and g, f = f AND g quietly means f = (f AND g). A little later I’ll show you how the language’s own authors fell for this rule.

Pure functions and value-returning procedures

Functions in Yellow are pure: they can’t change their parameters, and they can assign only to their own local variables. So given the same arguments, a function always returns the same result, wherever you call it. Ironman didn’t require this; SRI went further on its own. For anything that has to change state, like “give me the next ticket number”, there are procedures that return a value:

FUNCTION Square RETURNS INTEGER64 (CONST x: INTEGER64) RETURN x * x ENDFUNCTION Square; PROCEDURE NextTicket RETURNS INTEGER64 () ticket := ticket + 1; RETURN ticket ENDPROCEDURE NextTicket; 

Green, in 1979, settled this question in almost the same way, and Ada 83 dropped the distinction.

Templates that rewrite the text

Generic modules in Yellow are simpler than in the other three languages. A module template, TEMPLATE, is just text with parameters. The INSTANCE statement literally rewrites that text, substituting whatever it was given for the parameters, and only then translates the resulting module. Each instance becomes a separate module with its own state, and an error in the template body shows up only when an instance is created, just like C++ templates with their three-screen error messages. Blue is the opposite: requirements on the type are written in the NEEDS list and checked where the generic procedure is called.

Sections X.C–D of the yellow specification

Sections X.C–D of the yellow specification: an instance means exactly what the module would mean if it were written out again with the actual parameters substituted

Hoare’s monitors

Concurrency, on the other hand, turned out to be the best part of Yellow. Processes in it communicate only through monitors. A monitor, invented by Hoare and Per Brinch Hansen, is a module whose procedures run strictly one at a time, and inside it there are signals: queues in which a process can sleep until the event it needs. In Java and POSIX these queues are called condition variables. Here’s a solution to the classic readers and writers problem, the monitor from Hoare’s 1974 paper, rewritten in Yellow:

MONITOR ReadersAndWriters IMPORT INTEGER64; EXPORT StartRead, EndRead, StartWrite, EndWrite; VAR readers: INTEGER64 := 0; busy: BOOLEAN := FALSE; okToRead, okToWrite: SIGNAL; PROCEDURE StartRead () IF busy OR AWAITED(okToWrite) THEN WAIT(okToRead) ENDIF; readers := readers + 1; SEND(okToRead); RETURN ENDPROCEDURE StartRead; PROCEDURE EndRead () readers := readers - 1; IF readers = 0 THEN SEND(okToWrite) ENDIF; RETURN ENDPROCEDURE EndRead; ... ENDMONITOR ReadersAndWriters; 

Signals in Yellow work exactly the way Hoare described them. SEND hands the monitor directly to the process it wakes, and the sender waits until that process leaves the monitor or goes back to sleep. That’s why the woken process can check its condition with IF rather than WHILE: between the signal and the wake-up, nobody can sneak in and spoil things again. In 1980, Xerox chose a different variant for its Mesa language, where a signal is only a hint and the woken process must recheck the condition in a loop. That variant is the one that caught on: it’s how wait and notify work in Java and how POSIX condition variables work. Everyone who has written Java knows about the while around wait, and in Yellow that loop isn’t needed. The price is discipline: you may send a signal only when the condition really holds. And if you add a watchdog that wakes a waiter on a timeout while the condition is still false, then even in Yellow you’ll have to recheck the condition after waking up.

Waiting also has a rank: WAIT(s, rank) queues the process by number, and SEND wakes the process with the lowest rank. AWAITED(s) asks whether anyone is waiting for that signal. And a signal can be bound to an interrupt address, in which case the hardware itself sends it.

An example from the yellow language's tutorial

An example from the yellow language’s tutorial: a real-time clock monitor rewritten from Wirth’s Modula. The clock process waits for a signal from the timer and wakes everyone waiting for the next tick

For anyone who finds a monitor too heavy, there are also binary semaphores with CLAIM and RELEASE. But, as you’ll see later, they’re best left alone.

Time you can stop

Last of all, here’s the thing in Yellow that genuinely surprised me. Any BEGIN ... END block can be marked SIMULATED_TIME, and then the processes inside it don’t run simultaneously but take turns, like parts of one ordinary program. Each runs until it starts waiting for something, and only then does the processor move on to the next one. Inside the block there’s its own artificial time. Every statement takes zero units of that time except DELAY(n), which takes exactly n, and the clock moves forward only when every process inside the block is waiting for something.

Section IX.B.3 of the yellow specification

Section IX.B.3 of the yellow specification: SIMULATED_TIME before BEGIN, and every statement takes zero units of time except DELAY(n)

In other words, a 1978 language has simulation with controlled time built in. Ironman did ask for a “clock for simulation”, and the blue design answered with a promise to write a simulation module like the one in Simula, the Norwegian simulation language that object-oriented programming grew out of. Yellow, instead, made it a language construct you can wrap around any piece of a real program. Today people build entire separate systems for the same purpose. The developers of the FoundationDB database built all of their testing on this kind of simulation: the program runs on an artificial clock, the network and disks are replaced by models, and any run can be replayed step by step. A separate company later grew out of that work, selling such an environment for other people’s programs. Yellow is, of course, nowhere near that: the specification doesn’t fix the order in which processes run, and the language doesn’t model hardware faults at all. But a clock that moves only when the program wants it to is already there.

My own project, by the way, rests on the same trick. Programs in all four languages run on a virtual clock, and the scheduler always picks processes in the same order, so any failure reproduces to the millisecond. Since my clocks are virtual everywhere anyway, SIMULATED_TIME in my compiler does what the specification asks for on top of that: inside such a block, processes don’t preempt each other when their time slice runs out and switch only when one of them starts waiting.

The same problems in four languages

According to the red team’s recollections, the 1978 reviewers split the four designs into two pairs: the conservative Blue and Red, and the ambitious, “academic” Yellow and Green. One language from each pair went on to the second round. Now that all four work, we can check that the split wasn’t arbitrary, and the easiest way to do that is with a single example.

The two pairs of 1978

The two pairs of 1978: the conservative Blue and Red, the ambitious Yellow and Green, each with its own way to synchronize

It’s the same example as in the Blue section. Two processes take turns adding 10 to a shared balance and take a lock so they don’t get in each other’s way. The first grabs the lock and fails before it can let go. Will the second one get the lock? This is anything but an academic question: in any system with locks, from an operating system kernel to a database, the first thing people ask is what happens to a lock when its owner dies. It’ll come up again in the Kubernetes section.

In Red, the lock is a REGION, and it’s released however the block ends:

REGION d DO DELAY(5); IF id = 1 THEN RAISE X_RANGE; END IF; balance := balance + 10; END REGION; 

In Green, as of 1979, and in Ada 83, a lock is a separate server task with two entries, SEIZE and RELEASE. The server simply waits for a RELEASE call and knows nothing else:

task body LOCK is begin loop accept SEIZE; accept RELEASE; end loop; end LOCK; ... LOCK.SEIZE; begin delay 0.005 * SECONDS; if ID = 1 then raise RANGE_ERROR; end if; BALANCE := BALANCE + 10; LOCK.RELEASE; exception when RANGE_ERROR => LOG("worker 1 failed while holding the lock"); end; 

In Blue, as we’ve already seen, the lock is released when a path ends abnormally, as long as it’s a REGION semaphore; the full program is in the Blue section. Yellow gives two answers, and they’re opposites. A monitor is freed if a monitor procedure ends with an exception, while a binary semaphore with CLAIM and RELEASE is never freed at all:

MONITOR Account ... PROCEDURE Update (CONST id: INTEGER64) DELAY(5); IF id = 1 THEN PROPAGATE_EXCEPTION OUT_OF_RANGE ENDIF; balance := balance + 10; RETURN ENDPROCEDURE Update; ... ENDMONITOR Account; 

Here’s what these programs print. If the second process still hasn’t got the lock after a hundred milliseconds, the program gives up and sums up. Red:

[1 ms] worker 1 holds the lock [6 ms] worker 1 failed inside the region [6 ms] worker 2 holds the lock [11 ms] both workers are through, balance 110: the region released the lock for the failed one 

Green:

[1 ms] worker 1 holds the lock [6 ms] worker 1 failed while holding the lock [100 ms] 1 of 2 workers through, balance 100: worker 2 still waits on SEIZE, nothing released the lock 

Blue:

[1 ms] worker 1 holds the semaphore [6 ms] worker 1 fails holding it [6 ms] worker 2 holds the semaphore [11 ms] the block signals FAILED: worker 1 ended abnormally [11 ms] both workers are through, balance 110: the path's end released its REGION semaphore 

Yellow:

[1 ms] worker 1 holds the monitor [6 ms] worker 1 failed inside the monitor [6 ms] worker 2 holds the monitor [11 ms] both workers are through, balance 110: leaving the monitor by an exception gave it up [11 ms] worker 3 claimed the semaphore [16 ms] worker 3 failed between CLAIM and RELEASE [112 ms] worker 4 asked 100 times: no exception gives a semaphore back 

To be fair, in the green program the process could call RELEASE itself in its exception handler, and in the yellow one you could do the same with the semaphore. But that’s manual work, and it’s easy to forget. More importantly, it doesn’t help when the process doesn’t fail with an exception but is killed from the outside: in Green and in Ada an aborted task runs no handlers, and the lock is lost for good. So the whole difference comes down to who is responsible for releasing the lock, the programmer or the language.

Three of the four languages take that job on themselves, each in its own way. Red ties the release to the program text: leave the REGION, and the lock is free. Blue ties it to the life of a path: the path dies, and its locks are free, though its signals aren’t. Yellow ties it to the module boundary: if an exception carries a process out of a monitor, the monitor is free. Only in Green, the language that went on to win, does the language not release the lock by itself, because it has no separate mechanism for shared data. A lock there is a task like any other, and it knows nothing about its client’s death. Ada got such a mechanism, the protected object, only in 1995.

There’s one more detail that only the blue program shows: the block learned that the first path had died and said so. In the other languages the failing process caught the error itself, and if it hadn’t, the task would simply have terminated quietly and nobody would ever have known.

The readers and writers problem

The second example is the classic readers and writers problem. Three readers arrive at milliseconds 0, 1 and 3, the writer at millisecond 2, and reading and writing each take ten milliseconds. In a good solution the readers read at the same time, but a reader who arrives after the writer can’t overtake it; otherwise, with a steady stream of readers, the writer would never get its turn.

Solution in the repository Readers read concurrently A late reader overtakes the waiting writer Everything don...Source:https://dev.to/tym83/paleocomputing-part-4-two-more-adas-rebuilding-the-blue-and-yellow-languages-the-pentagon-44o9

Related posts