Skip to content

Instantly share code, notes, and snippets.

@BRonen
Created November 21, 2025 05:26
Show Gist options
  • Select an option

  • Save BRonen/b394bd2151a7926aed588c309e70f97b to your computer and use it in GitHub Desktop.

Select an option

Save BRonen/b394bd2151a7926aed588c309e70f97b to your computer and use it in GitHub Desktop.
Compare-and-Swap invalidation experiment using clojure atoms
(ns atom-cas
(:require [clojure.core.async :as async]))
(def a (atom 0))
(defn updater [current-value]
(prn "Thread: " (Thread/currentThread))
(prn "Current: " current-value)
(Thread/sleep 500)
(inc current-value))
(defn run-test []
(println "Start: " @a)
(let [futures (doall (for [i (range 5)]
(future
(swap! a updater))))]
(doseq [f futures] @f))
(prn "End: " @a)
(prn "Expected: 5")
(reset! a 0))
(comment
(run-test)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment