<story><title>Linus Torvalds on semaphores (1999)</title><url>http://yarchive.net/comp/linux/semaphores.html</url></story><parent_chain></parent_chain><comment><author>Animats</author><text>Here&amp;#x27;s Dijkstra&amp;#x27;s original paper on P and V (in Dutch), from about 1963.&lt;p&gt;&lt;a href=&quot;http://www.cs.utexas.edu/users/EWD/transcriptions/EWD00xx/EWD35.html&quot; rel=&quot;nofollow&quot;&gt;http:&amp;#x2F;&amp;#x2F;www.cs.utexas.edu&amp;#x2F;users&amp;#x2F;EWD&amp;#x2F;transcriptions&amp;#x2F;EWD00xx&amp;#x2F;EW...&lt;/a&gt;&lt;p&gt;Here is a implementation of P and V, the original counted semaphore primitives, from 1972.&lt;p&gt;&lt;a href=&quot;http://www.fourmilab.ch/documents/univac/fang/&quot; rel=&quot;nofollow&quot;&gt;http:&amp;#x2F;&amp;#x2F;www.fourmilab.ch&amp;#x2F;documents&amp;#x2F;univac&amp;#x2F;fang&amp;#x2F;&lt;/a&gt;&lt;p&gt;This is UNIVAC 1108 assembly code.  Along with P and V is the code for bounded buffers, with the operations &amp;quot;PUT&amp;quot; and &amp;quot;GET&amp;quot;.  Bounded buffers are what Go calls &amp;quot;channels&amp;quot;.  Note how simple they are if you have P and V.  That code even works on multiprocessors. There&amp;#x27;s one semaphore for &amp;quot;queue full&amp;quot; and one for &amp;quot;queue empty&amp;quot;.  PUT does a P on &amp;quot;queue full&amp;quot;, puts on an item, and does a V on &amp;quot;queue empty&amp;quot;.  GET does a P on &amp;quot;queue empty&amp;quot;, takes off an item, and does a V on &amp;quot;queue full&amp;quot;.  It&amp;#x27;s very simple.  That&amp;#x27;s the real use case for P and V. Linus&amp;#x27; note indicates that in 1999 he didn&amp;#x27;t know this.&lt;p&gt;(I didn&amp;#x27;t write those primitives, but I&amp;#x27;ve used that code, and once ported it to a Pascal compiler I adapted to handle concurrency.)&lt;p&gt;This stuff was all well understood four decades ago.  Much of it was forgotten outside the mainframe world, because threads and multiprocessors didn&amp;#x27;t make it to microprocessors for several more decades.  UNIX, for a long time, had very primitive synchronization primitives. Early UNIX didn&amp;#x27;t have threads, and even after it got threads, it took years before the locking primitives settled down.  The DOS&amp;#x2F;Windows world didn&amp;#x27;t get them until Windows NT, circa 1993.&lt;p&gt;It&amp;#x27;s been amusing to me to see bounded buffers resurface in Go.  They&amp;#x27;re quite useful, and I&amp;#x27;ve been using them in concurrent programs for many years.</text></comment>
<story><title>Linus Torvalds on semaphores (1999)</title><url>http://yarchive.net/comp/linux/semaphores.html</url></story><parent_chain></parent_chain><comment><author>robert_tweed</author><text>&lt;i&gt;&amp;quot;Dijkstra was probably a
bit heavy on drugs or something (I think the official explanation is
that P and V are the first letters in some Dutch words, but I personally
find the drug overdose story much more believable).&amp;quot;&lt;/i&gt;&lt;p&gt;Quotes like this are why I always read what Linus has to say, regardless of whether the subject is relevant to my life in the slightest.&lt;p&gt;Edit: Yes people, those Dutch words exist! I get it! I&amp;#x27;m sure Linus was well aware of that when he made this remark. However, the point Linus was making (in a humorous way) was that like most computer scientists &amp;#x2F; mathematicians, Dijkstra was overly fond of obscure, single-letter names, which nobody ever intuitively understands. Whereas the names &amp;quot;up&amp;quot; and &amp;quot;down&amp;quot; (see the rest of Linus&amp;#x27; quote) are far more intuitive. Personally, I would argue that &amp;quot;hold&amp;quot; and &amp;quot;release&amp;quot; convey the intent in a clearer, more abstract way.</text></comment>