On Tuesday I misread that the Papers We Love meet up that scheduled to take place on 11/19 was actually happening today. I think I messed up because I only looked at the day instead of the date. Silly me.
This mix-up gave me an excuse (like I needed one) to read a research paper on the bus ride back from work. I chose to read “Threads Cannot Be Implemented As a Library” by Hans-J.Boehm.
The main argument laid forth in this paper is that for concurrency to be defined and used correctly in a language it must be part of the language specification and cannot be bolted on as a library. The motivating example used throughout the paper is that of C and the Pthreads library. Pthreads was probably my first introduction to concurrency (it might have been Java threads; I don’t remember) which is one of the reasons why I thought this paper was really interesting. It’s also something that I’ve not really thought of — I know that Pthreads is just a library but for some reason I felt that it was a part of C.
To illustrate his point the author gives three categories of errors that arise when threads are a library. In essence all three errors stem from compiler optimizations. Because the compiler is not aware of threading/concurrency semantics (because it is not a part of the language specification) it makes optimizations that can lead to performance boosts in single threaded programs, but could cause problems in multi-threaded programs. The paper ends with a section on performance showing how expensive concurrency primitives are, and what can be done in C++ to come up with a standard for threading. You can find details about the C++11 memory model here.
This paper is short (10 pages!) and very easy to read. Even though it is about 10 years old the ideas and thoughts presented in it are still valid, especially if you’re coding in C. Or if you plan on inventing a new programming language. I highly recommend reading it.
One thought on “Library”