3 ms·
The main use of hardware TM at the moment I believe is lock elision--your threading library can try to use a transaction, and only resort to a lock if the trans
by jcranmer 7y ago
The main use of hardware TM at the moment I believe is lock elision--your threading library can try to use a transaction, and only resort to a lock if the transaction aborts.
Hardware TM I think jumped the gun for implementation. On its own, it has a simple memory model, but when you try to interact it with the usual memory model, the interactions are difficult and complicated (the paper here shows that ARM's proposal for HTM makes lock elision impossible). There is also the annoyance that you have a maximum size of transaction region, but predicting your transaction region size and making your code handle different hardware region sizes are both tricky.
- foobiekr 7y agoThis sounds like a weird variant of double checked locking where the check-and-take is part of the transaction. That sounds like it breaks composability. Can you provide s reference to the use of transactions that fall back to locks?
- jcranmer 7y agoI'm not an expert on the x86 implementation, but my understanding of its implementation of hardware lock elision in this: A lock in x86 is usually implemented as an atomic variable, with a read-modify-write to acquire it and another to release it, with appropriate memory barriers to squelch incorrect memory reordering. Hardware lock elision is described with a prefix to these read-modify-write instructions to indicate that it's a lock acquire instruction or a lock release instruction. What the hardware will do is first ignore the lock and execute the code as a transaction. If the transaction fails (which usually means another processor is writing to the same memory location), it restarts at the lock-acquire instruction and executes the regular locking code. As you might imagine, this has all sorts of potentially crazy interactions with the regular memory model. The article that's linked here is a paper that built a full memory model of both the normal hardware/C++11 memory model and the transactional memory semantics, and then they use it to see if the hardware lock elision is actually correct. They found that the ARM model is broken, but the POWER and x86 hardware lock elision is correct.
- foobiekr 7y agoThanks, that makes more sense.