Ask HN: What code samples should programmers read?
Fang.[1]<p>Fang is a utility program for UNIVAC 1108 computers, written in 1972.  UNIVAC&#x27;s EXEC 8 had threads and async I&#x2F;O for user programs, decades before UNIX. The machines were shared-memory multiprocessors. FANG uses those capabilities to parallelize copying jobs.  The UNIVAC mainframes had plenty of I&#x2F;O parallelism and many I&#x2F;O devices, so this was a significant performance win.<p>See especially &quot;schprocs&quot;. Those are the classic primitives from Dijkstra: P, V, and bounded buffers.  That technology predates Go by 40 years.  Here&#x27;s Dijkstra&#x27;s P function:<p><pre><code>    .
    .
    .         DIJKSTRA P FUNCTION
    .
    .
    .         LA,U      A0,&lt;QUEUE&gt;
    .         LMJ       X11,P
    .         &lt;RETURN&gt;                      X5 DESTROYED
    .
    P*        TS        QHEAD,A0            LOCK THE QUEUE
              LX        X5,QN,A0            LOAD QUEUE COUNT (note: load)
              ANX,U     X5,1                BACK UP THE COUNT (note: Add Negative, i.e. subtract)
              SX        X5,QN,A0            REPLACE THE COUNT IN THE QUEUE (note: store)
              TN        X5                  DO WE NEED TO DEACTIVATE HIM ? (note: Test Negative)
              J         PDONE               NO.  SKIP DEACTIVATION (note: Jump, i.e. branch)
              ON        TSQ=0               (note: this is an assembly-time ifdef)
              LX        X5,QHL,A0           LOAD BACK LINK OF QUEUE
              SX        X5,QHL,X4           PUT INTO BACK LINK OF ACTIVITY
              SX        X4,QFL,X5           CHAIN ACTIVITY TO LAST ACTIVITY
              SA        A0,QFL,X4           CHAIN HEAD TO NEW ACTIVITY
              SX        X4,QHL,A0           MAKE THE NEW ACTIVITY LAST ON QUEUE
              CTS       QHEAD,A0            RELEASE PROTECTION ON QUEUE HEAD
    SCHDACT*  DACT$     .                   DEACTIVATE PROCESS (note: system call)
              OFF
              ON        TSQ                 (note: for later version of OS with alt wait fn)
              C$TSQ     QHEAD,A0            WAIT FOR C$TSA (note: system call)
              OFF
              J         0,X11               RETURN AFTER ACTIVATION
    .
    PDONE     CTS       QHEAD,A0            UNLOCK THE QUEUE (note: not a system call, just a macro. Stores 0.)
              J         0,X11               RETURN
</code></pre>
(Notes:<p>Instruction format is<p><pre><code>   OPERATOR  REG,OFFSET,INDEXREG
</code></pre>
The &quot;TS&quot; instruction is &quot;Test and Set&quot;. That&#x27;s atomic. If the flag is already set, an interrupt occurs and the OS does a
thread switch. CTS just clears the flag. Later versions of the
OS support C$TSQ and C$TSA, where the OS queues waiting test
and set operations.<p>X4 is the &quot;switch list&quot;, the local data for the thread.)<p>[1] <a href="https:&#x2F;&#x2F;www.fourmilab.ch&#x2F;documents&#x2F;univac&#x2F;fang&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.fourmilab.ch&#x2F;documents&#x2F;univac&#x2F;fang&#x2F;</a>