On being stateful (2008)
joeduffyblog.com
joeduffyblog.com
Despite being a C++ programmer I like using high level abstraction. I like being able to write a few lines and knowing what the result will be and having the computer just figure it out the details. Despite that I really want those abstractions to be as close to zero cost as possible. I also want to precisely know how to work with the contract the spec demands and the implementation reality requires, because performance is all too often a real concern for me.
STM has never had a role in any of that because it tries to be a panacea. It tries to fix everything for everybody. There is no way it can be an optimal (or even reasonable) solution for most problems).
I think me and the author would agree that naked mutexes are the gotos of threaded algorithms. Just as we replaced gotos with several kinds of loops, several kinds of functions, classes, lambdas and countless other more expressive tools, we will replace naked mutexes with a host of other tools. Have something you just want to run on some other hardware and get the answer from, try a future/promise. Have N units or identical work, try a parallel for or a one of the many GPU executors. Have a complex dependency chain of heterogeneous work, build a DAG of actors or other automata. Need something else, perhaps your threading primitive hasn't been invented yet.
[1]: http://www.informit.com/articles/article.aspx?p=1193856
Similarly for STM; it's only practical in a language with enough mutation control built into it that nobody will want to use it, i.e., Haskell. It can't be added to conventional languages. IIRC it was already looking pretty grim by 2008, but now it's certain; you can't bodge STM onto a conventional imperative language.