
Simon Peyton Jones 
273
Peyton Jones: But there’s something that stayed the same—the key on the 
book is guaranteed not to change somehow, right? So there’s a number of 
ways you could do this. One is you could say, “What you do when you 
replace it with a proxy is you don’t modify the library at all”—that’s 
unchanged. What you do is you modify the book itself. And you don’t 
modify its key field—you only modify its value field, where it’s currently 
living. Now the index can be reorganized while the book is somewhere else. 
That’s cool—and you can express that perfectly naturally. 
With STM, at the end the librarian looks through all the memory locations 
that he has read and sees if they contain now the same values that they did 
when he read them. So the locations that he has read will include the key 
field of the book because that determined where he put it. But he hasn’t 
read the contents of the book. So he’ll say, “Ah, this book—does this key 
field still contain 73; oh, yes it does.” 
But I don’t want to minimize the problem of starvation because it’s a bit 
insidious. You need good profiling tools that point you at transactions that 
are failing to commit because they keep getting bumped so that, rather than 
the program just silently not doing very much, you get some feedback about 
it. The same is true of a lock-based program. I hate it when those 
hourglasses appear. 
Seibel: I guess in locked-based programs we’ve just learned to try hold 
locks for as short a duration as possible since that will give us the least 
contention.
Peyton Jones: Right. But, of course, then it’s harder to program. Finer-
grained locking is tricky to get right. I think this is one of the huge wins of 
STM, is it gives you the fine granularity of very fine-grained locking along 
with very simple reasoning principles. 
Here’s a reasoning principle that STM gives you that locks absolutely do not. 
I’ll establish my top-level invariants—I’ve got a bunch of bank accounts, the 
total sum of money in all the bank accounts added together is N. Money 
moves between bank accounts—that’s all. So there’s my invariant. Any 
transaction assumes that invariant at the beginning and restores it at the 
end. How do you reason that it does? We look at any one transaction that 
says, “Take three out of that one and put three into that one.” Good,