diff options
author | lukechampine <luke.champine@gmail.com> | 2016-03-30 20:42:15 -0400 |
---|---|---|
committer | lukechampine <luke.champine@gmail.com> | 2016-03-30 20:42:15 -0400 |
commit | eb14808f905e96c9464e413a545b0185a22b6f2c (patch) | |
tree | e2cc0adeaa9d77979ffdf4eb8a8a0884d60e9306 /stm.go | |
parent | use atomic.Value for Vars (diff) | |
download | stm-eb14808f905e96c9464e413a545b0185a22b6f2c.tar.gz stm-eb14808f905e96c9464e413a545b0185a22b6f2c.tar.xz |
clarify caveat
Diffstat (limited to 'stm.go')
-rw-r--r-- | stm.go | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -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 |