The Little Book of Semaphores is a textbook that introduces the principles of synchronization for concurrent programming. In most computer science curricula, synchronization is a module in an Operating Systems class. OS textbooks present a standard set of problems with a standard set of solutions, but most students don't get a good understanding of the material or the ability to solve similar problems. The approach of this book is to identify patterns that are useful for a variety of synchronization problems and then show how they can be assembled into solutions. After each problem, the book offers a hint before showing a solution, giving students a better chance of discovering solutions on their own. The book covers the classical problems, including "Readers-writers," "Producer-consumer," and "Dining Philosophers." In addition, it collects a number of not-so-classical problems. *** Published under the terms of the GNU Free Documentation License. Money raised from the sale of this book supports the development of free software and documentation.
Allen Downey is a Professor Emeritus at Olin College and the author of a series of freetextbooks related to software and data science, including Think Python, Think Bayes, and Think Complexity, which are also published by O’Reilly Media. His blog, Probably Overthinking It, features articles on Bayesian probability and statistics. He holds a Ph.D. in computer science from U.C. Berkeley, and M.S. and B.S. degrees from MIT.
Whenever I write code to synchronize multiple threads, I always think, "There must be some method to this." I've been warned by the popular adage, "Any non-trivial multithreaded program has bugs," but I have no systematic way to think about synchronization that assures me I've handled all the cases. This book does not provide that method. What it *does* is to provide exercises, with solutions, that have developed my facility with thinking about synchronization, and have shown common synchronization patterns that should be applicable to almost any real-world problem.
Starting from the most basic cases, the book leads the reader step-by-step through a series of increasingly complex synchronization problems, each followed by a hint and finally a solution written in a Python-like pseudocode. Appendices show how to "clean up" Python's and C's threading libraries to better suit the author's tastes, and to better match the pseudocode solutions.
The classic synchronization problems included in most Computer Science curricula tend to use real-world objects to describe their constraints: E.g., philosophers are dining at a round table, and each needs two forks. Or, men and women form two lines and they must dance in pairs. In fact, the synchronization problems don't arise on dance floors but in operating systems and software applications, so the classic descriptions do more to confuse than to clarify. The author promises to present both the classic description and the actual software system it arose from, but in fact only the first few problems are presented this way. The more advanced problems (such as the dining philosophers) are not tied to software applications at all. I couldn't think of any use for the solutions so I felt comfortable skimming those later sections.
If you thoroughly absorb the first 10 problems or so, thinking hard and working out your own solutions, you'll gain some confidence and familiarity with synchronization which will serve you in nearly all software challenges you'll actually face. The book's "long tail" of theoretical puzzles is best left to grad students.
It's available as a free PDF download, so if you ever write multithreaded code you should give it a look.
I thought it would be boring. I am completely wrong. How could it be? It is filled with engaging puzzles based on a single almighty concept of semaphores. It contains classical puzzles and also the author's own puzzles. It is the ideal way to learn. If you love puzzles and you deal with multithreading, this is a must ~read~ solve
Честно говоря, примерно с пятой главы я перестал решать задачи, потому что 6 семафоров на задачу уже перебор(особенно для человека, который в продакшн не отправил ни одного семафора), но книга действительно понравилась, оставлю последние главы на пенсию.
I found this book helpful for passing my operative systems undergraduate exams, it is full of common semaphor use cases. Accompanied with pseudocode solutions this book made it easier for me to follow and understand the concept of syncrhonus and concurrent programming.
If you like to solve problems and at the same time understand the concurrency problems, this books is for you. Allen teaches semaphores and concurrency patterns through problems and solutions and best part is, you don't need to be computer science graduate to solve these problems.
If you are taking an Intro to Operating Systems course this short and concise book is far superior to the 1 or 2 lectures that you will get on the subject.