File tree Expand file tree Collapse file tree 1 file changed +2
-2
lines changed Expand file tree Collapse file tree 1 file changed +2
-2
lines changed Original file line number Diff line number Diff line change 92
92
93
93
That should work. Except we said we'd like these transfer to run concurrently,
94
94
and in parallel. With a single lock like that we'll only let one transfer take
95
- place at a time. Perhaps we need more locks? We could have one per account
95
+ place at a time. Perhaps we need more locks? We could have one per account:
96
96
97
97
``` ruby
98
98
a.lock.synchronize do
@@ -107,7 +107,7 @@ However this is vulnerable to deadlock. If we tried to transfer from a to b, at
107
107
the same time as from b to a, it's possible that the first transfer locks a, the
108
108
second transfer locks b, and then they both sit there waiting forever to get the
109
109
other lock. Perhaps we can solve that by applying a total ordering to the locks
110
- - always acquire them in the same order?
110
+ and always acquire them in the same order?
111
111
112
112
``` ruby
113
113
locks_needed = [a.lock, b.lock]
You can’t perform that action at this time.
0 commit comments