syzygy wrote:You have never heard about transactional memory?
No. Is that another physics-violating theoretical construct?
I believe current hardware implementations are pessimistic in that speculative stores won't be visible to other threads until the transaction is committed, but there is no fundamental reason why e.g. two cores on the same cpu (or maybe two hyperthreads on the same core) could not implement an optimistic version.
That it would deadlock both cores seems reason enough, for me.
For reasons that are still obscure (as nothing can ever be gained by it, and it always thoroughly wrecks things, most of all performance) you want speculatively executed stores to be seen by other cores. Then you have two choices:
1. Those other cores treat loading that data also as speculation, and must thus wait until the core that stored it commits it before it can commit any of the stuff that depended on it.
2. The other cores treat data from a speculative write as real.
(1) Leads to a deadlock, the causality chain load1 -> test1 -> store1 -> load2 -> test2 -> store2 -> load1 being looped, and all waiting for each other to be committed.
(2) Leads to total corruption of the operation of other cores, as they start acting on data that was never supposed to be there. Programs like:
Code: Select all
int start = false;
Thread 1:
if(false) start = true;
Thread2:
if(start) GlobalNuclearWar();
would not have the expected effect, because the compiler could apparently speculatively store 42 to start in thread 1.
I understand of course that adopting such a standard would make writing a universal compiler just a job of minutes. You just let it
speculate that each thread would crash, and starts filling the memory (in particular the part holding the code of other threads) with random data. So that these threads crash as well, and fill our code section with random data. Low and behold! The speculation was true! What a perfect translation of our SMP program.]!