Concurrent
Concurrent copied to clipboard
Using transactions from multiple threads
Hi, I am trying to use the STM system to run simultaneous transactions from multiple threads. Unfortunately it seems either my usage is incorrect, or my understanding of the API is. Can you please help me out ?
Code :
for _ in 1...3 {
Thread {
let _ =
transfer(from: alice, to: bob, amount: 100)
.then(transfer(from: bob, to: alice, amount: 20))
.then(deposit(into: bob, amount: 1000))
.then(transfer(from: bob, to: alice, amount: 500))
.atomically()
}.start()
}
Result : If fails on this pre-condition
precondition(transactionEnterSucceed, "Transaction already running on current thread")
@rhishikeshj The simple translation from F# didn't work, I'm working on a independent implementation