From eb14808f905e96c9464e413a545b0185a22b6f2c Mon Sep 17 00:00:00 2001 From: lukechampine Date: Wed, 30 Mar 2016 20:42:15 -0400 Subject: clarify caveat --- stm.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'stm.go') diff --git a/stm.go b/stm.go index aa65747..148a404 100644 --- a/stm.go +++ b/stm.go @@ -61,11 +61,12 @@ y, and block if both values are zero. // returns a transaction function. stm.Atomically(stm.Select(dec(x), dec(y))) -An important caveat: transactions must not have side effects! This is because a -transaction may be restarted several times before completing, meaning the side -effects may execute more than once. This will almost certainly cause incorrect -behavior. One common way to get around this is to build up a list of operations -to perform inside the transaction, and then perform them after the transaction +An important caveat: transactions must be idempotent (they should have the +same effect every time they are invoked). This is because a transaction may be +retried several times before successfully completing, meaning its side effects +may execute more than once. This will almost certainly cause incorrect +behavior. One common way to get around this is to build up a list of impure +operations inside the transaction, and then perform them after the transaction completes. The stm API tries to mimic that of Haskell's Control.Concurrent.STM, but this -- cgit v1.2.3