Concurrent icon indicating copy to clipboard operation
Concurrent copied to clipboard

Using transactions from multiple threads

Open rhishikeshj opened this issue 4 years ago • 1 comments

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 avatar Apr 12 '20 07:04 rhishikeshj

@rhishikeshj The simple translation from F# didn't work, I'm working on a independent implementation

wentingliu avatar Dec 30 '21 04:12 wentingliu