After a discussion in dcug about the write-skew anomaly, I wanted to write a program exhibiting the anomaly, together with a similar program using ensure to eliminate it.
My program doesn't work: it exhibits the anomaly, but ensure doesn't fix it, and neither does adding a validator to the refs. I'd like to know if it is a bug in my program, in my understanding of 'ensure' and/ or validators, or, finally, in Clojure. The program simulates the write-skew example from wikipedia: there are two accounts a1 and a2 initially holding $100 each, and the bank requires that @a1 + @a2 >= 0 always. A user concurrently tries two transactions: one withdrawing $200 from a1 and one withdrawing $200 from a2. The bank code checks that @a1 + @a2 >= 200 before transferring any money. With serializable transaction-semantics, the bank's constraint is never violated; with snapshot-isolation semantics, it may be violated. I have four programs. The first is intended to exhibit the write-skew anomaly, and it works as intended: after running a few times, a state with @a1 = @a2 = -100 may be observed. http://paste.lisp.org/display/87117 The second is intended to elibinate the write-skew anomaly, by letting the changing transactions use ensure: http://paste.lisp.org/display/87117#1 The third program tries to eliminate the write-skew by using ref :validator instead (also ensures both refs!) http://paste.lisp.org/display/87117#2 Finally, I wrote a serialized version using an agent. As expected there is no write-skew. http://paste.lisp.org/display/87117#3 Help? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---