4 ms·
"and the code using that pattern can't actually be rolled back and retried, then the code is wrong." Well, yes, sure, that's easy to say, but the problem there
by jerf 15y ago
"and the code using that pattern can't actually be rolled back and retried, then the code is wrong."
Well, yes, sure, that's easy to say, but the problem there is when your base language has no way of detecting mutations that can't be rolled back, you can't help but write wrong code. You've been doing it since the day you picked up your first programming language, after all. And in theory, C arrays are perfectly safe because you will always pass around their lengths and check the length every time you so much as glance at the array, but in practice it's hopeless and the only practical solution for mere mortals is Don't do that. STM actually suffers from this even worse because if you actually want to take advantage of the composition promises (and if you aren't getting that why bother with STM in the first place), it only takes one bad case in one block of code, with no feedback to the programmer that an untracked effect has occurred at any point, to bring the whole thing down. One of the whole points is that you can write transactional code that calls other transactional code and it's all supposed to Just Work in a way lock-based code can't be composed together, so a single transaction may run all over the program just like a single function call can.
I can't hardly get my coworkers to properly encode their HTML, and you expect me to teach them about managing effects in a language that doesn't even acknowledge they exist as a distinct category of things?
You can solve this by adding a concept of "effect" to your language, as Haskell does... but once you do that, you no longer have the same language. Not even close. None of the old libraries will work, more semantics will have to be tweaked, the change will ripple everywhere in both semantics and probably syntax, new coding patterns will have to be learned (and worse, unlearned!)... unless someone's come up with a really big breakthrough that everybody up to this point has missed.
It's not a hardware problem, it's a semantic problem.
- jbri 15y agoIt seems like your complaint is "shitty programmers will still do it wrong". Does this "solve" the concurrency problem so that the most craptastic of copy-pasters can write high-performance concurrent code? Hell no. But it never pretended to in the first place, so that's pretty much irrelevant. It's like saying that doing graphics processing in dedicated hardware is bad because a lot of programmers are awful at coding 3D graphics. Even if you look at this just as a convenience for compiler writers, this would significantly improve the performance for anything that does do transactional memory properly.
- pjscott 15y agoIt's also a very useful primitive for people writing shared data structures, like concurrent hash tables or multiple-producer, multiple-consumer priority queues.
- jerf 15y agoThe problem with C arrays is not that shitty programmers get them wrong; the problem with C arrays is that only programming gods walking amongst men get them right. Managing effects in a language without any support for it, and decades of work put into making effects easier to implicitly apply without even having to think about it, is at least as hard. There's more to the programming difficulty scale than "shitty" and "competent" and it's not a good idea to count on any programming technique that can only be used by the gods amongst men... even if you are one! (Writing raw string-concatenation-based HTML output safely is another example. No, you can't do it correctly in a large code base without help. Even if you are that smart, you aren't that superhumanly diligent.)
- rbranson 15y agoI think you misunderstand STM. STM is used to group and apply a few micro-operations, within a single function, but not many or over multiple functions, certainly not over multiple modules. It is not really for rebounding from exceptions in the general sense, as transactions are used in an RDBMS. It's more to keep the system in a stable state, something locks are usually used for in multi-threaded programming. Just as locks are best applied as fine-grained as possible, so is STM.
- jrockway 15y agoThe goal of STM is to be composable, unlike locks: http://research.microsoft.com/en-us/um/people/simonpj/papers/stm/stm.pdf http://research.microsoft.com/en-us/um/people/simonpj/papers... The title of the paper is "Compsable Memory Transactions", and here's an excerpt: As we show, STM can be expressed particularly elegantly in a declarative language, and we are able to use Haskell’s type system to give far stronger guarantees than are conventionally possible. Furthermore transactions are compositional: small transactions can be glued together to form larger transactions.
- rbranson 15y agoSure, just as you'd understand a library or function to be "thread safe" it could be considered "transactional." I'm saying STM is to be used in as fine a grain as possible, even if it's composing "larger grains." Just as thread-safety doesn't mean entering a shared, global critical section at the beginning of every function, STM doesn't mean that every block of code should be wrapped in a transaction. STM should really only be applied to writes that would cause the system to be in an improper state if partially applied.
- jrockway 15y agoI'm not sure I agree. Reads also need to be in transactions in order to prevent deadlocks. I think the paper I linked is pretty accessible, so it's worth a read. I agree that most of your program should be pure, though, but that's just a good practice in general, not something tied to transactional memory.