4 ms·
This is exactly the scenario that Simon Peyton Jones used to motivate Software Transactional Memory (STM) in his 2007 "Beautiful Concurrency" paper: http://res
by ky3 12y ago
This is exactly the scenario that Simon Peyton Jones used to motivate Software Transactional Memory (STM) in his 2007 "Beautiful Concurrency" paper:
http://research.microsoft.com/pubs/74063/beautiful.pdf http://research.microsoft.com/pubs/74063/beautiful.pdf
or we push locking up the chain to their users
That's still prone to deadlock. Suppose each account has its own lock. Then to transfer from account A to B, the code might look like
A.lock(); B.lock();
A.withdraw( amount );
B.deposit( amount );
B.unlock(); A.unlock();
If another transfer occurs in the reverse direction at exactly the same time, the code deadlocks in the middle of the first line.
SPJ explains this and other cases pretty well.